微信小程序获取列表键值对

[
   {"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"]

 

posted @ 2023-10-11 00:18  睡觉不困  阅读(97)  评论(0编辑  收藏  举报