My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

What's the most efficient way of finding an object by property in an array of objects?

Koh Wang's photo
Koh Wang
·Oct 4, 2016

In terms of time complexity (and language agnostic), what algorithm will be most efficient.

let array = [ { a : 1, b : 2}, {a : 3, b : 6}, {a : 4, b : -1} .... N ]

Now imagine a function, find({a : 3}) i.e. find the position of the object in the array where property a is equals to 3. What algorithm (pseudo code) will be the fastest here?