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

      发布在:前端技术      评论:0 条评论
<p style="margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">var json = {&quot;key1&quot;:&quot;val1&quot;,&quot;key2&quot;:&quot;val2&quot;,&quot;key3&quot;:&quot;val3&quot;};</p><p style="margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">if(json.hasOwnProperty(&quot;key1&quot;)){</p><p style="margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">console.log(json[&quot;key1]);</p><p style="margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">}</p><p><br/></p>
相关文章
热门推荐