0
    let tempProducts = [];
storeProducts.forEach((item) => {
  const singleItem = { ...item };
  tempProducts = [...tempProducts, singleItem]; <----- This Line
});

What does the above indicated line mean? It looks like new ES6 syntax, but unlike anything I have seen before. Can anyone explain this to me please?

1 Answers1

-1

It creates a new array which consists of the items from tempProducts and the singleItem.

It has the same result as

tempProducts.concat(singleItem);

The (quite modern) syntax with the three dots is called 'spreading', the ... is the spread operator.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268