找到数组里某个元素并返回该对象
用jquery里的filter方法
var taskid = $("#hidTaskId").val(); $.getJSON('requestAddress?taskId=' + taskid +'&stepId=4687', function(data){ var IsNewSysArr = data.filter(function(elem, index,data){ return elem.propId == 'isNewVer'; }); });
ES6中也有许多遍历的方法
https://blog.csdn.net/chelen_jak/article/details/78840550
Filter
例:在一串数组里面找到有某个属性的对象(返回的是数组)
var tableData = [ { groupId: 11, groupName: '小组221' },{ groupId: 12, groupName: '小组2311' },{ groupId: 13, groupName: '小组1231' }, ] var groupName = '小组1231'; var result = tableData.filter(item => { return item['groupName'] == groupName }) tableData = [...result];
Find
例:在一串数组里面找到有某个属性的对象(返回的是对象)
var submitData = { id: 1, text: 'test' } var dataArr = [ { id: 1, text: 'test' },{ id: 2, text: 'test' } ] var tmpObj = dataArr.find((item)=>{ return item['id'] == submitData['id'] })
标签:groupName,item,元素,var,数组,某个,id From: https://www.cnblogs.com/whqbk/p/17085473.html