将对象数组转换为数组

时间:2018-11-17 23:32:01

标签: javascript arrays object pup

我试图将测试数组中每个对象的“计数”键转换为新数组,所以最终得到类似

newCount = [0,0,0,0]

'/device:GPU:0'

2 个答案:

答案 0 :(得分:2)

您可以在测试数组上使用Array.prototype.map()来提取每个对象的count属性值:

const newCount = test.map(t => t.count);

希望有帮助!

答案 1 :(得分:0)

您可以在数组上使用地图:

const newarray = test.map(item => item.count);

Array map documentation

相关问题