const array = [5, 2, 8, 11, 42];
const sortedArray = array.sort((a, b) => a - b);
console.log(sortedArray); // [2, 5, 8, 11 , 42]
let a19 = {
"red": ['Akademmistechko', 'Nyvky', 'Universytet', 'Lisova'],
"blue": ['Minska', 'Obolon', 'Pochaina', 'Holosiivska'],
"green": ['Syrets', 'Zoloti Vorota', 'Klovska', 'Vidubichi']
}
function f19() {
let i19 = document.querySelector('.i-19').value;
let out19 = document.querySelector('.out-19');
let out = '';
for (let key in a19) {
for (const item of a19[key]) {
if (item.toLowerCase() == i19 || item == i19) {
out += key;
}
}
}
out19.style.background = out;
out19.style.height = "100px";
}
document.querySelector('.b-19').onclick = f19;
<html>
<head>
</head>
<body>
<button class="submitClass" >Нажми меня</button>
<input type="text" value="Донецк" class = "block">
<div class="city-name"></div>
<div class="city-temp"></div>
<div class="disclaimer"></div>
<div class="imgWrapp"></div>
<script>
let cities = ["Киев","Харьков","Львов", "Донецк","Запорожье","Кривой рог","Николаев","Мариуполь","Луганск","Севастополь","Винница","Симферополь","Херсон","Полтава", "Чернигов","Черкасы","Хмельницкий"]
function click () {
let input = document.querySelector(".block").value;
let cityId;
for(let i = 0; i < cities.length; i++) {
if(cities.includes(input)) {
cityId = input;
break;
}
}
fetch(`http://api.openweathermap.org/data/2.5/weather?q=${cityId}&appid=88d4aef74677c233e595e292f6d361d6`)
.then(function(resp) {return resp.json()})
.then(function(data) {
console.log(data)
document.querySelector(".city-name").textContent = data.name;
document.querySelector(".city-temp").innerHTML = Math.round(data.main.temp - 273) + "°";
document.querySelector(".disclaimer").textContent = data.weather[0]['description'];
let imgWrap;
imgWrap = `<img src="https://openweathermap.org/img/wn/${data.weather[0]['icon']}@2x.png">`;
document.querySelector('.imgWrapp').innerHTML = imgWrap;
})
.catch(function() {
})
console.log(cityId);
}
document.querySelector(".submitClass").onclick = click;
</script>
</body>
</html>
false
и число 0
, которые не будем считать пустым значением.var data = {1: "", 2: "123", 3:""};
function anyEmpty(obj) {
var p, v;
for( p in obj) {
v = obj[p];
if( !obj.hasOwnProperty(p)) continue;
if( v === false || v === 0) continue;
if( !v ) return true;
}
return false;
}
anyEmpty(data) // true