Help getting array in right order

<html>
<head><meta charset="utf-8"></head>
<body>
<p id="products"></p>
<script type="text/javascript">

var A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","r","s","t","u","v","y","z"];
var D = ["printer", "tablet", "router", "laptop", "cable", "camera"];
var num=[];
for(var i=0; i<D.length; i++){
num[i]=[];
for(var k=0; k<D[i].length; k++){
num[i][k]=A.indexOf(D[i][k]);//A dizisinden harfin indeksini alıyoruz
}
}
alert(num.toSource());
// [[15, 16, 8, 13, 18, 4, 16], [18, 0, 1, 11, 4, 18], [16, 14, 19, 18, 4, 16], [11, 0, 15, 18, 14, 15], [2, 0, 1, 11, 4], [2, 0, 12, 4, 16, 0]]


</script>
</body>
</html>

I want this
[[2, 0, 1, 11, 4], [2, 0, 12, 4, 16, 0],[11, 0, 15, 18, 14, 15], [15, 16, 8, 13, 18, 4, 16],[16, 14, 19, 18, 4, 16], [18, 0, 1, 11, 4, 18] ]
instead of
[[15, 16, 8, 13, 18, 4, 16], [18, 0, 1, 11, 4, 18], [16, 14, 19, 18, 4, 16], [11, 0, 15, 18, 14, 15], [2, 0, 1, 11, 4], [2, 0, 12, 4, 16, 0]]
How can I do this?

Sort the variable D before running your for loop

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.