V
V
Vic Shostak2018-02-01 19:46:13
JavaScript
Vic Shostak, 2018-02-01 19:46:13

Filter multidimensional JSON array in vanilla JavaScript?

Good time!
There is such an array that arrives from the backend via the REST API (tourist industry):

[
  {
    "id": 1,
    "resort": "Сочи",
    "hotels": [
      [4, 100, 8100],
      [3, 80, 5399],
      [5, 20, 15399],
      [4, 180, 8399],
    ]
  },
  {
    "id": 2,
    "resort": "Пхукет",
    "hotels": [
      [1, 30, 10570],
      [3, 50, 12799],
    ]
  },
  
  // ...ещё около 50 стран...

]

The element hotelscontains hotels of this resort with information (let's take the first one as an example):
...
      [ 
        4,  // кол-во звёзд отеля
        100,  // кол-во номеров
        8100 // средняя стоимость номера
      ],
...

So here's how to get this most average room rate (the third element of each hotel), if only known:
  • Resort ID
  • hotel stars
  • number of rooms

For example:
I want to get the room rate in the Sochi resort, a 4 star hotel, where the number of rooms is 100.

Thanks in advance.
I will be glad to sensible comments!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kn1ght_t, 2018-02-02
@vikkyshostak

https://jsfiddle.net/vL4x8sy8/3/
*corrected correct links

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question