Skip to content
Advertisement

How to find item in array in React

I want to retrieve data from a json file and then match it with the value of an existing variable and if the variable value matches the data in json it will display a message “a” and if it does not match it will display a message “b”.

the json file is like this

JavaScript

Advertisement

Answer

What you want is to find a value in an array.

You can use includes

JavaScript

Same thing with indexOf

JavaScript

You can also try filter

JavaScript

And even find

JavaScript
Advertisement