Im trying to check an array for a value as such. not sure how to go about. If anyone could help that would be great.
var array1 = [0];
if (DONT KNOW WHAT TO SAY TO CHECK FOR 0 IN THE ARRAY) {
Do something
}
Im trying to check an array for a value as such. not sure how to go about. If anyone could help that would be great.
var array1 = [0];
if (DONT KNOW WHAT TO SAY TO CHECK FOR 0 IN THE ARRAY) {
Do something
}
simple like this
if (array1[0] == "0") {
//Do something
}
and if you have more values in your array you should use indexOf()
var array1 = [0, 3, 1, 4];
if (array1.indexOf(0) != -1) {
//Do something
}
DONT KNOW WHAT TO SAY TO CHECK FOR 0 IN THE ARRAY
If you want to check for 0
in the array1
(anywhere in the array), then use indexOf
if (array1.indexOf(0) != -1)
{
Do something
}
You need to access the array. If you have no idea what place the array is you need to go through the array.
for (var i = 0; i < array.length; i++) {
if (array[i] == 0) {
//Do all the things
}
}
Also you can do
for(var i in array){
if(array[i] == 0){
//Do all the things
}
}