Occasionally, I encounter a scenario where objects need to be pushed into a separate array based on the content of a looped array:
let customArray: any[];
_.forEach(iteratedArray, (item:any) => {
// some irrelevant code...
customArray.push(item.some.property);
});
The documentation states that Lodash's forEach() function only passes in 3 arguments - the value, an index, and a collection. Is there a method to ensure the scope of the customArray within the forEach()? Using 'var' results in a runtime error when it attempts to push items into the array. While I have managed to resolve the issue using a different approach, it is frustrating that such insistence cannot be enforced.