0

l have following data json keys objects

{
  "23ac54a": [
    25.226,
    54.9333
  ],
  "23ad09a": [
    24.9228,
    55.1319
  ],
  "23ad1b6": [
    24.8367,
    55.148
  ]
} 

l am trying to pass parameter from page 1 to page 2 . So if that parameter is same value in that data json above i want to get only data under that object key depending on same parameter coming from page 1 .

example if parameter from page 1 is 23ad09a and he is same in that data json i will take only data under this 23ad09a from data json above .

So my question is its possible to do that using if statement ? and if its how can i write functionality depending on my code below please ?

My code

this.Data = JSON.parse(data.data);
console.log(this.Data)
this.points = Object.keys(this.Data)
  .map(key => this.Data[key])
  .map((position) => ({
    lat: position[1],
    lng: position[2],
  })).filter(position => position.lat && position.lng).forEach(i => {

      console.log(i.lat, i.lng)

      // our work is here


    })
1
  • question is unclear Commented Jan 28, 2020 at 13:56

1 Answer 1

1

If I get you right, you want to filter the data e.g. by key === "23ad09a" ?

I made a simple stackblitz to show you how to do this.

As I can see you use position[1] and position[2], but you should start at [0].

I added

.filter(key => key === '23ac54a')

where '23ac54a' can be replaced by a variable.

https://stackblitz.com/edit/typescript-aoh2h3

(don't forget to expand console to see the printed results in stackblitz)

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

1 Comment

your right that what l want . but on your way , i will getting only data under that object key 23ac54a example right ?

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.