js如何检测一个属性是否在json对象里
- in运算符
- hasOwnProperty()
- != undefined
//检测o对象里是否有属性a
var o={a:1,b:2,c:3};
console.log("a" in o);
console.log(o.hasOwnProperty("a"));
console.log(o.a != undefined);
//检测o对象里是否有属性a
var o={a:1,b:2,c:3};
console.log("a" in o);
console.log(o.hasOwnProperty("a"));
console.log(o.a != undefined);