-2

I am getting the error forEach is not a function. Can anyone please help? Basically i want to create a shallow copy of filteredSettlements and use that for iteration. Here is the code snippet for more details

const test = $.extend({}, test1);
test.forEach((test1) => {
 //anything
 });
user3681970
  • 1,201
  • 4
  • 19
  • 37
  • 3
    You're creating a new object, not an array. Objects do not have `forEach`. Did you mean `$.extend([], ...`? Or you can `Object.entries` or something over the object, if you want. – CertainPerformance Apr 25 '18 at 07:47
  • In simple words - filteredSettlementsForIteration is not an array. Foreach is applied to an array. Here you are looping through objects hence Foreach will not work as you are extending to objects. You can try using simple for loop. – Amit Kulat Apr 25 '18 at 09:00

2 Answers2

2

You are extending filteredSettlements into an Object {}. And object doesnt have forEach Method.

Array has forEach method

sridhar..
  • 1,945
  • 15
  • 19
0

I assume filteredSettlements is an array. Try this

const filteredSettlementsForIteration = filteredSettlements.slice();
filteredSettlementsForIteration.forEach(settlement => {});
soyelmnd
  • 55
  • 7