Blondinka,
JSON структура неправильная. Должно быть так
cityList.json
[
{"_id":707860,"name":"Hurzuf","country":"UA","coord":{"lon":34.283333,"lat":44.549999}},
{"_id":519188,"name":"Novinki","country":"RU","coord":{"lon":37.666668,"lat":55.683334}},
{"_id":1283378,"name":"GorkhÄ","country":"NP","coord":{"lon":84.633331,"lat":28}},
{"_id":1270260,"name":"State of HaryÄna","country":"IN","coord":{"lon":76,"lat":29}},
{"_id":708546,"name":"Holubynka","country":"UA","coord":{"lon":33.900002,"lat":44.599998}},
{"_id":1283710,"name":"BÄgmatÄ« Zone","country":"NP","coord":{"lon":85.416664,"lat":28}},
{"_id":529334,"name":"Mar’ina Roshcha","country":"RU","coord":{"lon":37.611111,"lat":55.796391}}
]
.js
function get(url) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function() {
if (req.status == 200) {
resolve(JSON.parse(req.response));
}
else {
reject(Error(req.statusText));
}
};
req.onerror = function() {
reject(Error("Сетевая ошибка"));
};
req.send();
});
}
get('cityList.json').then(function(response) {
"use strict";
let findName = 'Hurzuf',
idx = response.findIndex(obj => Object.is(obj.name, findName));
alert(idx);
}, function(error) {
console.error("Не удалось выполнить!", error);
});