JS之判断json对象中是否含有某个key值

var json = {"key1":"val1","key2":"val2","key3":"val3"};

if(json.hasOwnProperty("key1")){

console.log(json["key1]);

}

resoult:

>>val1

 

转载于:https://www.cnblogs.com/xiaozhouyuxiaohou/p/9945492.html

你可能感兴趣的:(JS之判断json对象中是否含有某个key值)