how to access and sort 2d array in javascript -


i'm writing script initalize 2d array in javascript reading txt file. here portions of code

var neighbor = {}; var temp = new array(); neighbor[nodemap[ temparray[0]]] = temp; //nodemap[ temparray[0]] integer neighbor[nodemap[temparray[0]]]. push(nodemap[temparray[1]]); neighbor[nodemap[temparray[0]]]. push(nodemap[temparray[2]]); .... // continue add value 

then want access , sort array,

for (var = 0; < n_count; i++); {   (var k = 0; k < neighbor[i].length; k++);     neighbor[k].sort(function(a,b){return - b}) } 

however, got error neighbor[i] unidentified. please show me how fix that?

your neighbor "array" object literal. way should loop on neighbor is:

for (var key in neighbor) {     var cur = neighbor[key];     cur.sort(function (a,b) {         return - b;     }); } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -