Nested forEach: Uncaught TypeError: data.forEach is not a function

I do not want to use any loop or any of the usual loops, I try to use forEach, but I get an error

Uncaught TypeError: data.forEach is not a function

return falsyData.map(function(data) {
  data.forEach(function(key) {
    if (key.match(reg)) {
      return key;
    }
  });
});

but if I do this, this will work:

return falsyData.map(function(data) {
  for (var key in data) {
    if (key.match(reg)) {
      return key;
    }
  }
});

why?

+4
source share
1 answer

data- object - forEachonly works with array types. You must use a loop for..into iterate over the keys of the object.

+6
source

Source: https://habr.com/ru/post/1605605/


All Articles