2 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
嘗試
if?(Object.values(file.something).includes(s))
通過使用object.values()
方法,您僅查詢對象值
const obj = {
? ?"something": {
? ? ? "hey":? ? ? "15145143",
? ? ? "foo":? ? ? "32431451",
? ? ? "test":? ? ?"34131343",
? ? ? "anything": "12341123"
? ?}
}
console.log('Does object include 15145143?', Object.values(obj.something).includes('15145143'));
console.log('Does object include 123?', Object.values(obj.something).includes('123'));

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果您想將字符串與值完全匹配,請使用
stringToMatch = 's'
console.log(Object.values(yourJson.something).includes(stringToMatch ))
如果您希望它匹配值的子字符串,則使用
stringToMatch = 's'
console.log(Object.values(yourJson.something).some(key => key.includes(stringToMatch)))
添加回答
舉報(bào)