后台传入的json数据,前端jquery如何取出所有type=1的title啊?

[{"content":"1","create_time":"2018-02-27 15:31:54","id":"0a4faa259fdf4e46b7a8ee371651b0d1","state":0,"title":"1","type":1},{"content":"1","create_time":"2018-02-27 15:32:17","id":"1c8f1404256a407d984e109e8117e827","state":0,"title":"1","type":1},{"content":"1","create_time":"2018-02-27 17:39:08","id":"1de747cb35884682afecea7e2d2dc092","state":0,"title":"1","type":1},{"content":"1","create_time":"2018-02-27 15:32:52","id":"4b4f712d995d4c66b54925a20d8d1c63","state":0,"title":"1","type":1},{"content":"3","create_time":"2018-02-27 17:45:20","id":"59ceded6b3024b3b95bfb1b59619027e","state":0,"title":"3","type":1},{"content":"<p>??????</p><p>???</p><p>&nbsp; &nbsp;??</p>","create_time":"2018-02-27 17:46:04","id":"5ad093e29a404578aa1c3b1c1fe5e477","state":0,"title":"??????","type":2},{"content":"<p>???</p><p>???</p><p>&nbsp; &nbsp; &nbsp; &nbsp;??</p>","create_time":"2018-02-27 17:16:48","id":"6c95cfc93369474bb4f00085fe36e7d3","state":0,"title":"3","type":1},{"content":"3","create_time":"2018-02-27 17:44:24","id":"81871baf05fb44b38d0dd028d91cc2dd","state":0,"title":"3","type":1},{"content":"3","create_time":"2018-02-27 17:06:23","id":"98b15a3b69ea4d6db26ea76b86e6ce7a","state":0,"title":"3","type":1},{"content":"2","create_time":"2018-02-27 16:46:41","id":"fe2823ef07bd48acbeadf48a6e7ff85c","state":0,"title":"2","type":1}]

慕侠2389804
浏览 734回答 5
5回答

青春有我

json.filter(function(item){&nbsp; &nbsp; return item.type===1;}).map(function(item){&nbsp; &nbsp; return item.title})

万千封印

&nbsp; var result = [] // 存储所有type为1的title&nbsp; for (var i = 0; i < list.length; i++) {&nbsp; &nbsp; var item = list[i]&nbsp; &nbsp; if (item.type === 1) {&nbsp; &nbsp; &nbsp; result.push(item.title)&nbsp; &nbsp; }&nbsp; }

江户川乱折腾

看了前面大神们的回答,所用到的方法大体差不多,这里我就推荐一个插件吧&nbsp;linq.js&nbsp;然后过滤的代码你就可以这样去写:Enumerable.From(json).Where("$.type&nbsp;===&nbsp;1").Select("$.title").ToArray();推荐文章:玩转 linq.js。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript