【问题标题】:Is there a way to get all this datas out and have them in an array [closed]有没有办法将所有这些数据取出并将它们放在一个数组中[关闭]
【发布时间】:2021-03-06 12:23:19
【问题描述】:
[{…}, {…}]

这是我拥有的数据结构

当我打开对象时,我有这个 0:{名称:“电台”,总数:11800} 1:{名称:“Billboard”,总数:350000}

【问题讨论】:

  • 看起来他们已经在我的数组中了。
  • 我想把名字放在不同的数组中,而总数在不同的数组中
  • 我想把名字放在不同的数组中,而总数在不同的数组中
  • 请以minimal reproducible example 显示您的确切原始对象、您确切期望的结果以及您解决它的尝试。见How to Ask。谢谢。

标签: arrays reactjs function object methods


【解决方案1】:

你在找这样的东西吗

let arr = [{name: "Radio", total: 11800}, {name: "Billboard", total: 350000}]

let names = arr.map(a=> a.name);
console.log(names);

let totals = arr.map(a=> a.total);
console.log(totals);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 2017-12-31
    • 2019-03-09
    相关资源
    最近更新 更多