MJ
asked on
Determine if value/index exists in an array?
What is the best way to detect if I'm getting the values I expect in an array or if it is missing? for example;
var myArr = ['value0-0'];
var newValues = ['value1-0',1];
myArr.push(newValues);
newValues = ['value2-0',1];
myArr.push(newValues);
var newValues = ['value3-0',0];
myArr.push(newValues);
var newValues = ['value4-0'];
myArr.push(newValues);
This could go on in any order etc. But I want to check to ensure that there is a second value? Can I do something like:
for (var i = 0; i < myArr.length; i++) {
if((typeof (myArr[i][1])) !== 'undefined'){
... then do something
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Then I would go with the function. And if you are doing anything with the input server side with your database, make sure you double check it there as the js function can easily be worked around.
ASKER