Is there a way to update a specific property in every element of an array to match its index? I attempted the following approach:
static reindexComponentsOnMultiplePages(components) {
return components.forEach((el, idx) => (el.componentIndex = idx));
}
However, this returned undefined. Here is how my current array looks like:
components = [
[ {...}, {...}, {...} ],
[ {...}, {...}, {...} ]
]
I expected each property in every element of the array to be updated accordingly. The method was called like so:
pageComponents = MyService.reindexComponentsOnMultiplePages(pageComponents);