javascript - accessing all of my elements in a multi-dimensional array with multiple loops. Why is this coming out as undefined? -
here's have, have 3-dimensional array variations of name. whole thing looks this.
var array = [['kenny', 'kenney'],['ken','ken'],['kenneth', 'kenneth']];
now, there's nothing wrong can tell comes do. i'm trying utilize loop loop through of @ once of these elements show up. here's wrote down myself..
for(var = 0; < array.length; i++) { for(var j = 0; j < array.length[i]; j++) { for(var k = 0; k < array.length[i][j]; k++) { console.log(array[i][j][k]); } } };
what comes undefined. doing wrong? in advance, guys.
you have 2 issues here. first, trying go 3 "levels" deep if 3-dimensional array, 2-dimensional.
you need array[i].length
instead of array.length[i]
var array = [ ['kenny', 'kenney'], ['ken', 'ken'], ['kenneth', 'kenneth'] ]; (var = 0; < array.length; i++) { (var j = 0; j < array[i].length; j++) { console.log(array[i][j]); } };
Comments
Post a Comment