-6

I have such type of array

How to access Viena

There could be a lot of cities

[{"Viena":[{"date":"2018-11-10","time":"17:45","price":599,"to_city":"Viena","wday":"saturday"},{..},{..}],{"Paris":[{..}]} ]
Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
bro
  • 1

1 Answers1

0

You can use Array.filter for this.

var data = [{"Viena":[{"date":"2018-11-10","time":"17:45","price":599,"to_city":"Viena","wday":"saturday"}]},{"Paris":[{"date":"2018-11-10","time":"17:45","price":599,"to_city":"Viena","wday":"saturday"}]}];

var result = data.filter(function(value){return Object.keys(value).indexOf("Viena") != -1;});

console.log(result[0]);
Nishant Dixit
  • 5,388
  • 5
  • 17
  • 29