Use a for
loop on the object to check that value exist in name
property or not:(在对象上使用for
循环检查name
属性中是否存在该值:)
var obj = { 123: { id: 123, name: 'abc' }, 456: { id: 456, name: 'def' }, 789: { id: 789, name: 'ghi' } }; var checkVal = 'def'; let match = false; for(var objKey in obj) { if(obj[objKey].name === checkVal) { match = true; } } console.log('found ', match);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…