Find value in an array of object
Let's take an example as follows:
Now you have arrObj and you want to check whether Rahul name is present or not and return that object from an array.
Now we will see it with looping to find the value.
The output will be as follows:
Now if we use ES6 then our code will be only one line which as follows:
But if you want to find the index of the value then you can use the following code to find the index of it.
var searchIndex = arrObj.findIndex(x => x.name == 'Rahul')
So as you have seen the code you can easily get value from an array of object.