Tutorialsplane

ReactJS check element exists in Array


You can use array indexOf method to check whether an element exists in Array or not. Here in this tutorial, we are going to explain how you can use this method to check if array contains value. You can use our online editor to edit and run the code online.


ReactJS check element exists in Array JavaScript Example

Array indexOf method returns -1 if element is not found in array else it returns index of element. Here is an example of Array indexOf method.

Example:


Try it ยป

Output of above example-

ReactJs Blog