Gunakan flat() 和 includes() Rujukan mudah disediakan untuk anda
function weatherCodes(){
let codes = [{sunny:[1001]},{cloudy:[1002,1003]}]
let theCode = 1003
return codes.some(c => Object.values(c).flat().includes(theCode));
};
console.log(weatherCodes());
Pilihan lain
function weatherCodes(){
let codes = [{sunny:[1001]},{cloudy:[1002,1003]}]
let theCode = 1003
let values = codes.flatMap(c => Object.values(c)).flat()
return values.includes(theCode)
};
console.log(weatherCodes());
Gunakan
flat()
和includes()
Rujukan mudah disediakan untuk andaPilihan lain