Array.prototype.forEachbeginnerconst result = {}
['a', 'b', 'c'].forEach((v, i) => { result[i] = v })
// result β {0:'a', 1:'b', 2:'c'}Use forEach() to build an object or other data structure by iterating over array elements.
forEach can be used to collect property values from an array of objects into a new array.
Challenge: Implement collectStrings(items) that uses forEach to collect all label values into a string array.
collectStrings([{label:'a'},{label:'b'}]) // β ['a', 'b']
collectStrings([]) // β []