0

enter image description here

this is what i am looking for

          markers: marker[] = [
        {
      lat: 18.533989,
      lng: 73.825592,

     },
      {
        lat: 18.540474,
       lng: 73.837510,
         label: 'B',
      },
       {
         lat: 18.540972,
        lng: 73.832146,
       label: 'C'
       }
     ]

 }

this is what i have tried

for (let i = 0; i < res.length; i++) {
        // Iterate over numeric indexes from 0 to 5, as everyone expects.
        let newobj = res[i].destinationAddress.location.coordinates;
        console.log(newobj);
        for(let j = 0; j < res.length; j ++){
          this.markersArr.push(newobj[j]);
        }

i am using angular 6 i need to convert json obj into array

4
  • this is not java Commented Jun 19, 2018 at 4:50
  • You should start by creating the object {lat, lng} that you want to push in the array. Commented Jun 19, 2018 at 4:51
  • Can you be a bit more specific of what the input is? You say they are different arrays, but then you seem to be iterating over one. Commented Jun 19, 2018 at 4:53
  • you can use new ES2018 object spread over operator (...spread) and combine your arrays Commented Jun 19, 2018 at 4:58

1 Answer 1

1

Try this code inside you inner loop.

const [lat, lng] = newobj[j];
this.markersArr.push({
  lat : lat,
  lng : lng,
  label : 'C' // or whatever value you want to add
})
Sign up to request clarification or add additional context in comments.

Comments

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.