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());
另一种选择
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());
使用
flat()
和includes()
为您提供的简单参考另一种选择