How to check if a element is there in an array in javascript

Code examples

11
0

get if there is a value in an array node js

myArray = Array(/*element1, element2, etc...*/);

// If the array 'myArray' contains the element 'valueWeSearch'
if(myArray.includes(valueWeSearch))
{
 	// Do something
}
3
0

javascript check if in array

var extensions = ["image/jpeg","image/png","image/gif"];          
if(extensions.indexOf("myfiletype") === -1){
	alert("Image must be .png, .jpg or .gif");
} 

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................