Jquery check if value exists in Array Example
In this post we will give you information about Jquery check if value exists in Array Example. Hear we will give you detail about Jquery check if value exists in Array ExampleAnd how to use it also give you demo for it if it is necessary.
If you need to check if value exists in jquery array then you can do it using jquery inarray function. $.inArray will help you to find and check if value is exists 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:
Example:
<!DOCTYPE html>
<html>
<head>
<title>Jquery check if value exists in Array Example - ItSolutionStuff.com</title>
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
</head>
<body>
<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!');
}
</script>
</body>
</html>
I hope it can help you…
Hope this code and post will helped you for implement Jquery check if value exists in Array Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs