Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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.

The post How to find last index of element inside array by certain condition with JavaScript? appeared first on The Web Dev.



This post first appeared on The Web Dev, please read the originial post: here

Share the post

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

×

Subscribe to The Web Dev

Get updates delivered right to your inbox!

Thank you for your subscription

×