How to check whether the value exists in array ?

Asked on May 28, 2018
Hello,
I want to search particular value in array. For example I have array of users , I want to check particular user is present in that array.
My array is as follows:
- Array(5)
- 0:{id: "empty", name: "Choose one..."}
- 1:{id: "option_1", name: "shilpa"}
- 2:{id: "option_2", name: "anita"}
- 3:{id: "option_3", name: "admin"}
- 4:{id: "option_4", name: "user"}
- length:5
- __proto__:Array(0)
- Here I want to check whether the user "admin" exists in the array?
- I tried with following but it is returning the result as false:
- console.log(this.observedByProperties.includes('admin'));
- Can any one provide solution in this?
- Thanks & Regards
- Shilpa Kulkarni

Replied on May 29, 2018
Use find(), for example
let data = arrays.find(ob => ob['name'] === 'admin');
if data is null then no admin.

Replied on May 29, 2018
Thank you.