Say I have an Object with an array on it like so someObj.myArray.someFunc, how do you use the spread operator on it?
I'v tried myObj....myArray.someFunc() , myObj[...myArray].someFunc and
myArray = myObj.myArray ...myArray.someFunc
1 Answer 1
I suppose someFunc is method of Array.prototype (e.g. forEach, map, ...):
[...myObj.myArray].someFunc;
However, if someFunc is method of object in array, you can iterate array and just call it. E.g.:
myObj.myArray.forEach(item => item.someFunc());
answered Nov 3, 2016 at 16:28
madox2
52.3k21 gold badges106 silver badges101 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Rob Cha
oh shoot, I wasn't thinking clearly. I won't be able to use the spread operator as someFunc is defined on the objects in the array
lang-js
...is not an operator