Tim Jansen Tim Jansen - 1 year ago 82
HTML Question

Search through Object Array in Javascript

I am having an javascript array with objects in it:

var array;
array[{name: "Peter",class: "7"},{name: "Klaus",class: "3"}];

How to find out if in this array is the name Peter?

EDIT: I want to have something like this

if (array.find("Peter"))

Answer Source

Use find.

arr.find(row => row.name === 'Peter');

Don't forget to use the polyfill in the link if your targeted browsers don't support this method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download