-1

I was reading about understanding arrays in another link, but still stuck..

JavaScript Storing Data in 2-D Array

Javascript Appending to 2-D Array

understanding nested arrays in Javascript

The problem is, i have sample code that i want to learn, but when i did in different style(cz different situation), i got stuck. The sample problem is like : (uses f12 in browser to check console)

enter image description here

It looks different, but when i check inside it's the same..

enter image description here

Both arrays are created in different ways, the first one is (i want to make this) :

var datas = [
    ['Bondi Beach', -33.890542, 151.274856, 4],
    ['Coogee Beach', -33.923036, 151.259052, 5],
    ['Cronulla Beach', -34.028249, 151.157507, 3],
    ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
    ['Maroubra Beach', -33.950198, 151.259302, 1]
];

And the other array (my own method) :

mydatas=[];

and how i add this elements to this array is:

mydatas.push(newArr);


And my half code to compare it : (many other thing to do, but didnt connect to this problem)

var datas = [
    ['Bondi Beach', -33.890542, 151.274856, 4],
    ['Coogee Beach', -33.923036, 151.259052, 5],
    ['Cronulla Beach', -34.028249, 151.157507, 3],
    ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
    ['Maroubra Beach', -33.950198, 151.259302, 1]
];
var mydatas=[];
for(i=0;i<Oldarry.length;i++){
    //other proccess
    newArr = [address, latlng.lat(), latlng.lng(), (index+1)];
    mydatas.push(newArr);
}

console.log(datas);
console.log(datas[0]);
console.log(mydatas);
console.log(mydatas[0]);

The result is :

enter image description here

My question is how I could create the first array (datas). Thanks for any help.
*The strange in mydatas i can't access first array, but in second picture if i click in console there are 7 array inside..



my full code without api key: https://jsfiddle.net/n425qxgy/

Budi Mulyo
  • 384
  • 5
  • 22

2 Answers2

2

I couldn't understand what exactly you want? I hope this could help you

var datas = [
    ['Bondi Beach', -33.890542, 151.274856, 4],
    ['Coogee Beach', -33.923036, 151.259052, 5],
    ['Cronulla Beach', -34.028249, 151.157507, 3],
    ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
    ['Maroubra Beach', -33.950198, 151.259302, 1]
];
var mydatas=[];
for(i=0;i<datas.length;i++){
mydatas.push(datas[i]);
}
console.log(datas);
console.log(datas[0]);
console.log(mydatas);
console.log(mydatas[0]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
0

Have you tried doing the same tests in Chrome or Firefox? I am guessing you are using IE/Edge since you pressed F12. It could be a funny issue with the MS console which is treating adding to an array differently....but the same.

  • yep this is my problem, https://stackoverflow.com/questions/24175017/google-chrome-console-log-inconsistency-with-objects-and-arrays bacause my _other proccess_ is more longer than next code, js execute my next progress meanwhile _other proccess_ still unfinished.. – Budi Mulyo Nov 26 '18 at 09:28