数组如下[
{'admin':0,'del':6,'download':0,'move':16,'rename':0,'upload':0},
{'admin':0,'del':0,'download':2,'move':16,'rename':0,'upload':4},
{'admin':0,'del':0,'download':2,'move':16,'rename':0,'upload':0}
]对数组进行处理,每一项的对象中,例如,如果admin全部大于0,返回true,否则返回 false['admin':false,'del':false,'download':false,'move':true,'rename':false,'upload':false]有没有好的方法处理谢谢。
1 回答
繁星coding
TA贡献1797条经验 获得超4个赞
var a = [ {'admin':0,'del':6,'download':0,'move':'16','rename':0,'upload':0}, {'admin':0,'del':0,'download':2,'move':'16','rename':0,'upload':4}, {'admin':0,'del':0,'download':2,'move':'16','rename':0,'upload':0} ], result = {'admin':true,'del':true,'download':true,'move':true,'rename':true,'upload':true}var falseRes = a.reduce((sum = {}, item) => { var keys = Object.keys(item) let temp = {} keys.forEach((key) => { if (item[key] <= 0) { temp[key] = false } }) console.log('temp', temp) Object.assign(sum, temp) return sum },{})Object.assign(result, falseRes)
添加回答
举报
0/150
提交
取消