1

First of all: Plunkr Example is here <-- NOW: WORKING EXAMPLE (edited)

This is the data:

[
  {
    "label": "One",
    "value": 1
  }, 
  {
    "label": "Two",
    "value": 2
  }, 
  {
    "label": "Three",
    "value": 3
  }
]

This is the filter:

  http.get('./data.json')
  .map(data => data.json())
  .filter ( 
    (x,index) => return x[index].value === 2
  )
  .subscribe(data => this.d = data);

I would like to get as result:

{
  "label": "Two",
  "value": 2
}

Maybe I've a blackout, where is the mistake?

1
  • try a console log in filter just to check if thats what you're really receiving Commented Aug 30, 2016 at 14:36

1 Answer 1

1

In this case you can use .concatMap

http.get('./data.json')
  .map(res => res.json())
  .concatMap(res => res)
  .filter(x => x.value === 2)
  .subscribe(data => {
    this.d = data;
  });

Example

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.