-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/

5
  • Please post the code you attempted with input examples Commented Nov 26, 2018 at 7:45
  • my real input is excel spreadsheet, can i ask, how i can upload it ? thq for reply.. Commented Nov 26, 2018 at 8:19
  • 1
    Make a minimal reproducible example using csv for example. var data = `a,b,c,d\ne,f,g,h` Commented Nov 26, 2018 at 8:40
  • thanks, i need really patient, to solve my problem with creating my model question.. little pain.. hehe Commented Nov 26, 2018 at 8:50
  • when creating the model question, i understand the problem is in my array, and after some search, i found that is real problem, check the accept answer, btw thanks for help.. Commented Nov 26, 2018 at 9:33

2 Answers 2

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>

Sign up to request clarification or add additional context in comments.

3 Comments

yeah that's is my code, but i got different result, check my experiment..
btw, can you help me, what i must add to more easy to understand in my question,, thq for help..
you could use snippet for more detail ,edit your question and add snippet
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.

1 Comment

yep this is my problem, stackoverflow.com/questions/24175017/… bacause my other proccess is more longer than next code, js execute my next progress meanwhile other proccess still unfinished..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.