如何在JavaScript或jQuery中过滤JSON数据?

如何使用Javascript或jQuery过滤JSON数据?

这是我的JSON数据:

[{"name":"Lenovo Thinkpad 41A4298","website":"google"},

{"name":"Lenovo Thinkpad 41A2222","website":"google"},

{"name":"Lenovo Thinkpad 41Awww33","website":"yahoo"},

{"name":"Lenovo Thinkpad 41A424448","website":"google"},

{"name":"Lenovo Thinkpad 41A429rr8","website":"ebay"},

{"name":"Lenovo Thinkpad 41A429ff8","website":"ebay"},

{"name":"Lenovo Thinkpad 41A429ss8","website":"rediff"},

{"name":"Lenovo Thinkpad 41A429sg8","website":"yahoo"}]

JavaScript

obj1 = JSON.parse(jsondata);

现在我只想要包含网站的名称和网站数据等于

回答:

这是您应该怎么做的方法:(适用于Google查找)

$([

{"name":"Lenovo Thinkpad 41A4298","website":"google222"},

{"name":"Lenovo Thinkpad 41A2222","website":"google"}

])

.filter(function (i,n){

return n.website==='google';

});

解决方案:(Salman’s)

$.grep( [{"name":"Lenovo Thinkpad 41A4298","website":"google"},{"name":"Lenovo Thinkpad 41A2222","website":"google"}], function( n, i ) {

return n.website==='google';

});

以上是 如何在JavaScript或jQuery中过滤JSON数据? 的全部内容, 来源链接: utcz.com/qa/413998.html

回到顶部