- Сортировка массива объектов по свойству.
|
1 2 3 4 5 6 7 8 9 10 11 |
let newFilterCities = e.data.cityList.sort(function (a, b) { var nameA = a.name.toLowerCase(), nameB = b.name.toLowerCase(); if (nameA < nameB) //сортируем строки по возрастанию return -1 if (nameA > nameB) return 1 return 0 // Никакой сортировки }), |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
initCities = [ "Москва", "Санкт-Петербург" ]; let firstCities = newFilterCities.filter(function(item){ if (item.name === initCities[0] || item.name === initCities[1]) { return true; } }); let otherCities = newFilterCities.filter(function(item){ if (item.name !== initCities[0] && item.name !== initCities[1]) { return true; } }); |
