S
S
Sergey Valitov2017-01-27 15:35:39
JavaScript
Sergey Valitov, 2017-01-27 15:35:39

How to form such an array in js?

Hello! Guys, help. Question: How to form an array of this format?

var locations = [
      ['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]
    ];

If initially there is an array
locations = [];
How to add an array to an array so that there is such a structure? I tried locations.push([val1, val2, val3]), but nothing was shown when iterating over, although console.log displayed everything, all internal elements.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ildar Gizetdinov, 2017-01-27
@serejatoje

Iterate like this

for (var key in locations) {
    var loc = locations[key];
    var locName = loc[0];

    console.log(locName );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question