Check if value exists jQuery in Array – jQuery.inArray()

Today, We want to share with you Check if value exists jQuery in Array – jQuery.inArray() JavaScript.In this post we will show you Check if value exists in Array – jQuery and JavaScript, hear for How to check if the object/element exist in JavaScript and jQuery we will give you demo and example for implement.In this post, we will learn about check if value already exists in array javascript with an example.

Check if value exists jQuery in Array – jQuery.inArray() JavaScript

There are the Following The simple About Check if value exists jQuery in Array – jQuery.inArray() JavaScript Full Information With Example and source code.

As I will cover this Post with live Working example to develop jquery inarray and jquery in array function, so the some Tutorial Steps for this example is following below.

  • Loop in jQuery/JavaScript
  • Array.indexOf()
  • jquery inarray method of jQuery.inArray()
  • Example – jquery inarray and Check if value exists jQuery in Array
Read Also:  Multi Dimensional Array Sorting in Php

Step 1. JavaScript Loop

JavaScript Loop

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as JavaScript Loop for Check if value exists jQuery in Array – jQuery.inArray() JavaScript.

<script type='text/javascript'>

 var devloper_array = ['disha','Bhakti','dhaval','jaydeep','Mayur rajpoot','chirag'];
 
 function loopByCheckArray(value,arr){
  var check_val = 'Not any exist';
 
  for(var i=0; i<arr.length; i++){
   var dev = arr[i];
   if(dev == value){
    check_val = 'Exist';
    break;
   }
  }

  return check_val;
 }
 console.log('check_val : ' + loopByCheckArray('disha', devloper_array) );
 console.log('check_val : ' + loopByCheckArray('farrukh', devloper_array) );
</script>

Step 2. Array.indexOf() in javascript – jquery in array

<script type='text/javascript'>

 var devloper_array = ['disha','Bhakti','dhaval','jaydeep','Mayur rajpoot','chirag'];
 
 
var liveMyStrTxt = "pakainfo Blog";

// Search in Array
console.log( 'My Array Place index : ' + devloper_array.indexOf('jaydeep') );
console.log( 'My Array Place index : ' + devloper_array.indexOf('krunal') );

// Search in String
console.log( 'My Array Place index : ' + liveMyStrTxt.indexOf('o') );

</script>

Step 3.jQuery.inArray() in jQuery

<script type='text/javascript'>

 var devloper_array = ['disha','Bhakti','dhaval','jaydeep','Mayur rajpoot','chirag'];
 
 
var liveMyStrTxt = "pakainfo Blog";

// Search in Array
console.log( 'My Array Place index : ' + jQuery.inArray('jaydeep',devloper_array) );
console.log( 'My Array Place index : ' + jQuery.inArray('krunal',devloper_array) );

// Search in String
console.log( 'My Array Place index : ' + jQuery.inArray('o',devloper_array) );

</script>

Step 4. Check if value exists jQuery in Array – jQuery.inArray() Example

HTML Part

<input id="person_name" type="text">
<input id="live_name_check" type="button" value="Check">

jquery Part

$(document).ready(function() {
    var devlopers = ['jaydeep', 'kajal', 'ankit', 'bhakti', 'krunal', 'milan', 'chirag', 'dhaval'];

    $('#live_name_check').click(function() {
        var yournm = $('#person_name').val();
        if (jQuery.inArray(yournm, devlopers)!='-1') {
            alert(yournm + ' in the array(devlopers)!');
        } else {
            alert(yournm + ' Sorry not in the array...');
        }
    });
});

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  ERROR 1118 (42000) Row size too large

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Check if value exists jQuery in Array – jQuery.inArray() JavaScript.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.