If you are familiar with PHP, where you can use the in_array() function to search value in the Array, and it returns the Boolean value ( TRUE or FALSE ).

There are inbuilt methods in jQuery and JavaScript that return the index position of the value which you can use for the search.

1. Loop

First start with a loop.

You can easily find the value within an Array by traversing on the Array and check for the value.

Completed Code

<script type='text/javascript'>

var names_arr = ['sonarika','yogesh','sumit','sonarika','vijay','anil'];
 
function checkValue(value,arr){
  var status = 'Not exist';
 
  for(var i=0; i<arr.length; i++){
    var name = arr[i];
    if(name == value){
      status = 'Exist';
      break;
    }
  }

  return status;
}
console.log('status : ' + checkValue('sonarika', names_arr) );
console.log('status : ' + checkValue('mayank', names_arr) );
</script>

Output

status : Exist
status : Not exist

For making your searching process simpler you can use jQuery and JavaScript inbuilt function.

2. Array.indexOf()

It is a JavaScript method that returns the index position of the value. If it doesn’t find the value then it returns -1.

It works both with string and an Array.

Syntax –

value-from-which-search.indexOf( search-value );

Completed Code

<script type='text/javascript'>
var names_arr = ['sonarika','yogesh','sumit','vijay','anil'];
var text = "Sonarika Bhadoria";

// Search in Array
console.log( 'Index : ' + names_arr.indexOf('sumit') );
console.log( 'Index : ' + names_arr.indexOf('vishal') );

// Search in String
console.log( 'Index : ' + text.indexOf('a') );

</script>

Output

Index : 2
Index : -1
Index : 3

3. jQuery.inArray()

It is a jQuery function that returns the index position of the value when it finds the value otherwise -1.

It also works with string and an Array.

Syntax –

jQuery.inArray( search-value, value-from-which-search);
<script type='text/javascript'>
var names_arr = ['sonarika','yogesh','sumit','vijay','anil'];
var text = "Yogesh singh";
// Searching in Array
console.log( 'Index : ' + jQuery.inArray('sumit', names_arr) );
console.log( 'Index : ' + jQuery.inArray('vishal', names_arr ));
 
// Searching in String variable
console.log( 'Index : ' + jQuery.inArray( "e", text ));

</script>

Output

Index : 2
Index : -1
Index : 3