How to find last index of element inside array by certain condition with JavaScript?

To find last index of element inside array by certain condition with JavaScript, we use the map and lastIndexOf methods.

For instance, we write

const lastIndex = elements.map((e) => e.a).lastIndexOf("something");

to call map with a callback that returns property a‘s value in each object e in elements.

Then we call lastIndexOf to get the last index of the a value that equals 'something' in the returned array.