Forum Discussion
The expression language is a functional subset of JavaScript, so often times you can search for the JavaScript solution to a problem and make some small changes to make it work.
In this case, you’ll want to use the ‘map()’ method on arrays to transform each element:
The ‘map()’ method takes an arrow function that will be passed the element in the array and the index of that element. So, we can extend() the existing element to add in the index that is passed into the callback function.
The result looks like this:
$.array1.map((elem, elemIndex) => elem.extend({index: elemIndex}))
Related Content
- 2 years ago
- 7 months ago
- 3 years ago