-1

I am having issues filtering this results by id

 "sectors": [
{
  "id": 1,
  "slug": "pilgrimage",
  "name": "Pilgrimage",
  "city_id": "1"
},
{
  "id": 2,
  "slug": "travel-preparation",
  "name": "Travel Preparation",
  "city_id": "2"
},
{
  "id": 3,
  "slug": "the-people",
  "name": "The People",
  "city_id": "1"
}
]

How will i filter this response by Id

Aᴍɪʀ
  • 7,623
  • 3
  • 38
  • 52
user6601176
  • 17
  • 1
  • 9

1 Answers1

0

I don't think i understand you completly, do you want get one element of this array by him id?

if I`m correctly here the solution:

 var request = function(id){

    for(var i = 0; i < object.length; i++){
        if(object[i].id == id){
            console.log(object[i])
        }
    }
}

them when you call the function like request(2); return you object...

Shukizu
  • 56
  • 1
  • 5
  • okay so it worked but i am having an issue – user6601176 Dec 25 '16 at 18:55
  • can you be more expecific in what issue you got? – Shukizu Dec 26 '16 at 01:31
  • The result shows up three times and i cant you variable id – user6601176 Dec 26 '16 at 05:32
  • – user6601176 Dec 26 '16 at 05:41