Here are my code:
var nestedArr = [[1, 2, 3], [5, 2, 1, 4]];
var result;
for (var a = 0; a < nestedArr.length; a++) { // iterate nestedArr
for (var b = 0; b < nestedArr[a].length; b++) {
if (nestedArr[a+1].includes(nestedArr[a][b])) {
result.push(nestedArr[a][b]);
}
}
}
Output: Error: Cannot read property 'includes' of undefined
. But at least I can make sure several things:
1. includes()
method exists for array in JavaScript
2. Run a single statement nestedArr[a+1];
in console give me the array [5, 2, 1, 4]
So, I really don't understand the Error
? Please help me figure out this. Thanks.