0

I want to understand why the ...list - spread syntax - (I believe it is spread because it deals with an iterable) is being added to the list this way. Does this mean list in collected in an array and pushed into the tempLists?

              const tempLists = [];

              // eslint-disable-next-line no-restricted-syntax
              for (const list of response.data.lists) {
                tempLists.push({ ...list, items: [] });
              }
tksilicon
  • 3,276
  • 3
  • 24
  • 36
  • That looks like *object spread*, not iterable/array spread. It shallow clones the `list` object (by taking its enumerable own properties), adds an `items` property, and pushes the resulting new object to `tempLists` – CertainPerformance Mar 12 '20 at 07:20
  • @CertainPerformance I get it now. It takes the enumerable properties of the list object and adds an items property which is an empty array and pushes the object which is a new list to the tempLists array. Thanks. – tksilicon Mar 12 '20 at 07:30

0 Answers0