check if value exists in array javascript example

July 15, 2019 | Category : Javascript JQuery

In this example, i will show you how to check if value exists in array or not in javascript. we can check if value exist in json array using inArray() of javascript. you can see bellow example to checking javascript json array value exist or not.

$.inArray function will return the index of element. If element not exist in given array it will return -1. So, we can check it very simply weather a value exist in array or not.

You can see bellow simple example how you can check with if condition:


<!DOCTYPE html>



<title>javascript check if value exists in Array Example -</title>

<script src="" type="text/javascript"></script>



<script type="text/javascript">

var myArray = ['PHP', 'Laravel', 'Codeigniter'];

console.log($.inArray('Laravel', myArray));

if ($.inArray('Laravel', myArray) >= 0) {

console.log('Laravel is exist!');

}else {

console.log('Laravel does not exist!');





I hope it can help you...