Помогите решить проблему, выпадает ошибка
Uncaught TypeError: Cannot read property '0' of undefined.
Ошибка именно в 40-ой строчке.
field = {
'1': { 1: b8, 2: d8, 3: f8, 4: h8 },
'2': { 5: a7, 6: c7, 7: e7, 8: g7 },
'3': { 9: b6, 10: d6, 11: f6, 12: h6 },
'4': { 13: a5, 14: c5, 15: e5, 16: g5 },
'5': { 17: b4, 18: d4, 19: f4, 20: h4 },
'6': { 21: a3, 22: c3, 23: e3, 24: g3 },
'7': { 25: b2, 26: d2, 27: f2, 28: h2 },
'8': { 29: a1, 30: c1, 31: e1, 32: g1 }
};
diagonals = {
'GoldWay': [ 29, 25, 22, 18, 15, 11, 8, 4 ],
'DoubleWayG1A7': [ 32, 27, 23, 18, 14, 9, 5 ],
'DoubleWayH2B8': [ 28, 24, 19, 15, 10, 6, 1 ],
'TripleWayC1A3': [ 30, 25, 21 ],
'TripleWayC1H6': [ 30, 26, 23, 19, 16, 12 ],
'TripleWayH6F8': [ 12, 8, 3 ],
'TripleWayA3F8': [ 21, 17, 14, 10, 7, 3 ],
'UltraWayA5D8': [ 13, 9, 6, 2 ],
'UltraWayH4D8': [ 20, 16, 11, 7, 2 ],
'UltraWayE1A5': [ 31, 26, 22, 17, 13 ],
'UltraWayE1H4': [ 31, 27, 24, 20 ]
};
testCourse (diagonals, field, 21);
function testCourse (arr, array, id){
cells = [];
for (key in arr){
for (value in arr[key]){
i = parseInt(value);
if (arr[key][value] === parseInt(id)){
console.log(i + ' ' + arr[key][value] + ' ' + arr[key][i + 1] + ' ' + value + ' ' +
searchCell (array, arr[key][value]) + ' ');
a = arr[key][value]; //Ошибка в этой строке
b = arr[key][i + 1];
c = searchCell (array, a);
d = searchCell (array, b);
if (c.color === 1 &&
d.color === 0){
cells.push(d);
}
}
}
}
return cells;
}