将值从对象数组复制到新数组

时间:2018-07-20 15:03:34

标签: javascript arrays object

我有以下对象数组:

  names: [
    {
      "first": "Bob",
      "last": "Newhart"
    },
    {
      "first": "Jerry",
      "last": "Seinfeld"
    },
    {
      "first": "Oprah",
      "last": "Winfrey"
    }
  ]

我想将其转换为如下所示的简单数组:

names: [ "Bob Newhart", "Jerry Seinfeld", "Oprah Winfrey"]

用JavaScript执行此操作的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

映射每个值并连接名字和姓氏

  @override
  Widget build(BuildContext context) {
    return new charts.PieChart(seriesList,
        animate: animate,
        defaultRenderer: new charts.ArcRendererConfig(arcWidth: 60));
  }

  new charts.Series<LinearSales, int>(
    id: 'Sales',
    domainFn: (LinearSales sales, _) => sales.year,
    measureFn: (LinearSales sales, _) => sales.sales,
    data: data,
  )

names.map(obj => obj.first + ' ' + obj.last)