json条件查询

完整Demo

<html> <head> <script type="text/javascript" src="http://www.w3school.com.cn/jquery/jquery.js"></script> <script type="text/javascript"> var arr = [ { "name": "apple", "count": "javascript" }, { "name": "orange", "count": "w3school" }, { "name": "pear", "count": "getJsonObj" }, { "name": "banner", "count": "w3school" } ]; function getJsonObj(keys) { var newArr = arr.filter(function (p) { return p.name == keys; }); return newArr; } var obj = getJsonObj("apple")[0]; var name = obj.name; var count = obj.count; console.log(name,count); </script> </head> <body> </body> </html>

 

posted @ 2019-06-28 08:20  大da脸  阅读(3527)  评论(0编辑  收藏  举报