I'm trying to loop through the columns, using a while loop but every time I'm getting an error and I was wondering if you guys can tell me what I did wrong. the code is this:
var arr = [
[['cat', 'fish'],['dog', 'meat']],
[['cat', 'toy'],['dog', 'bone']],
[['cat', 'fish'],['dog', 'bone']]
];
var position = 0;
//can I do this in stead?
//while(arr.length > position){
while(true){
var arrEnd = true;
for (var k = 0; k < arr.length; k++) {
if(arr.length > position){
arrEnd = false;
}
}
if(arrEnd){break;}
for(var i =0; i < arr.length;i++){
for(var j =0; j < arr.length;j++){
if(i != j && arr[i][position][1] == arr[j][position][1]){
console.log(arr[i][position]+'===='+arr[j][position]);
}
}
}
position++;
}
//Expected:
// "cat,fish====cat,fish" "cat,fish====cat,fish"
// "dog, bone====dog,bone" "dog, bone====dog,bone"
//Error getting: arr[i][position] is undefined
What is wrong? I can't see the issue.