Is there a forEach loop in Lodash for associative arrays? A function called "forEach", I discovered, works only for indexed arrays. For example, if I have an array myArray with values [1, 2, 3] and do
lodash.forEach(myArray, function(index) { console.log(index); });
and run the function (in Node ), I get the expected result:
1 2 3
However, when I try this with an associative array, it does not work:
lodash = require('lodash'); myArray = []; myArray['valOne'] = 1; myArray['valTwo'] = 2; myArray['valThree'] = 3; lodash.forEach(myArray, function(index) { console.log('7'); });
As you can see from running this in Node , the callback function does not work even if it contains something other than array elements. It seems he just missed the loop.
First of all, why is this happening? Secondly, is there another function included in Lodash for this problem, or, if not, is there a way to use the forEach to execute it without changing the original array in the process?
trysis
source share