1

I recieving a json to an

items:any = [];

items[0]['name']
items[0]['adres']
items[0]['lat']
items[0]['lng']

In this i have 4 keys and need only 2, lat and lng.

How can i make an markers array like this dynamic from the items in my app.component.ts?

markers = [
    {
        lat: 51.673858,
        lng: 7.815982
    },
    {
        lat: 51.373858,
        lng: 7.215982
    },
    {
        lat: 51.723858,
        lng: 7.895982
    }
]
1
  • Loop is one of the solutions Commented Oct 25, 2016 at 10:30

1 Answer 1

3
var n = 0;
var markers = items.map(item => {
    lat: item['lat'],
    lng: item['lng'],
    label: String.fromCharCode(65 + n++)
});

Btw, this is not related to Angular2 but TypeScript instead.

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

4 Comments

Ahah, almost there, how can i append an label: value , so the value has to be A, B , C , etc
I don't understand what you want to do.
google maps needs a "label", so by the first key i need an A and by the second B etc. var markers = items.map(item => { lat: item['lat'], lng: item['lng'], label: dynamic A,B,C, etc so by every row })
@Bas You can use String.fromCharCode().

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.