微信小程序获取列表键值对
以
[ {"id":"1","name":"1","value":"1"}, {"id":"2","name":"2","value":"2"}, ]
为例
1.仅获取关键字key
for (let i = 0, lenI = list.length; i < lenI; ++i) { console.log("keys",Object.keys(list[i])) }
结果为:
["id","name","value"]
["id","name","value"]
2.仅获取值
for (let i = 0, lenI = list.length; i < lenI; ++i) { console.log("values",Object.values(list[i])) }
结果为:
["1","1","1"]
["2","2","2"]