完整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>