📌  相关文章
📜  js 对象是否包含值 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:06.227000             🧑  作者: Mango

代码示例1
// You can turn the values of an Object into an array.
// Then test that a value is present:

// This assumes, that the Object is not nested
// and the value is an exact match:

var obj = { a: 'test1', b: 'test2' };

// Note that an array can only have positive index's; so
// checking for a negative index is a super valid way for getting a
// boolean value as a result for the check.
if (Object.values(obj).indexOf('test1') > -1) {
   console.log('Value exists!');
}