Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check if an array contains a specific string in jQuery?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 762
    Comment on it

    Sometimes we need to check if a particular string exists in an array or not, we can do this by using inArray() method of jQuery very easily.

    Example

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Demo</title>
      <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>
     <p id="message"></p>
    <script>
    var arr = [ "Canada", "London", "India" ];
    
    $("#message").text(jQuery.inArray( "India", arr ));
    
    </script>
    
    </body>
    </html>
    

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: