-1

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

新计数 =[0,0,0,0]

const test =  [
      {
        id: 0,
        count: 0,
        image: "",
        text: 'Some text about finn'
      },
      {
        id: 1,
        count: 0,
        image: "",
        text: 'Some text about daphne'
      },
      {
        id: 2,
        count: 0,
        image: "",
        text: 'Some text  finn'
      },
      {
        id: 3,
        count: 0,
        image: "",
        text: 'Some text  daphne'
      }
    ]
4

2 回答 2

2

You can use Array.prototype.map() on your test array to extract the count property value of each object:

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

Hopefully that helps!

于 2018-11-17T23:35:55.597 回答
0

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

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

数组映射文档

于 2018-11-17T23:40:50.043 回答