0

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

Rob Cha
  • 139
  • 12
  • What are you trying to do? –  Nov 03 '16 at 16:32
  • `...` is [not](https://stackoverflow.com/questions/35019557/using-spread-operator-multiple-times-in-javascript/35020522#35020522) [an operator](https://stackoverflow.com/questions/37151966/what-is-spreadelement-in-ecmascript-documentation-is-it-the-same-as-spread-oper/37152508#37152508) – Felix Kling Nov 03 '16 at 16:41

1 Answers1

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());
madox2
  • 49,493
  • 17
  • 99
  • 99
  • 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 – Rob Cha Nov 03 '16 at 16:33