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

2
  • What are you trying to do? Commented Nov 3, 2016 at 16:32
  • ... is not an operator Commented Nov 3, 2016 at 16:41

1 Answer 1

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());
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.