We would like to know how to search 2d array.
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from w w w . jav a2s . co m-->
var arr = [[2,3],[5,8],[1,1],[0,9],[5,7]];
document.writeln(arr.toString());
document.writeln('<br/>');
var x = 2;
var y = 3;
var found = false;
for(var k = 0; k < arr.length; k++){
if(arr[k][0] == x && arr[k][1] == y){
found = true;
}
}
if(found){
document.writeln('Found ['+x+','+y+'] in the array');
}else{
document.writeln('Could not find ['+x+','+y+'] in the array');
}
</script>
</head>
<body>
</body>
</html>
The code above is rendered as follows: