Skip to main content
edited body
Source Link
Aefits
  • 3.5k
  • 6
  • 33
  • 49

consider below code

var fruits = ["Banana", "Orange", "Apple", "Mango"]; var index = fruits.indexOf("Apple"); if(index===index != -1) { alert ("Apple found at " + index) } else { alert ("Apple not in exists") } 

array indexof returns index number(0 or 1 or 2) of the value if the value exists but returns -1 if the value does not exists.

thanks!

consider below code

var fruits = ["Banana", "Orange", "Apple", "Mango"]; var index = fruits.indexOf("Apple"); if(index=== -1) { alert ("Apple found at " + index) } else { alert ("Apple not in exists") } 

array indexof returns index number(0 or 1 or 2) of the value if the value exists but returns -1 if the value does not exists.

thanks!

consider below code

var fruits = ["Banana", "Orange", "Apple", "Mango"]; var index = fruits.indexOf("Apple"); if(index != -1) { alert ("Apple found at " + index) } else { alert ("Apple not in exists") } 

array indexof returns index number(0 or 1 or 2) of the value if the value exists but returns -1 if the value does not exists.

thanks!

Source Link
Aefits
  • 3.5k
  • 6
  • 33
  • 49

consider below code

var fruits = ["Banana", "Orange", "Apple", "Mango"]; var index = fruits.indexOf("Apple"); if(index=== -1) { alert ("Apple found at " + index) } else { alert ("Apple not in exists") } 

array indexof returns index number(0 or 1 or 2) of the value if the value exists but returns -1 if the value does not exists.

thanks!