ES5 风格的连接数组。将数组合并为一个

use*_*770 0 javascript arrays angularjs

我必须将数组块与 Angularjs 中的对象数组合并为单个数组。

我的输入数组将是这样的:

[
  [
    {
      "title": "asd",
      "description": "asd"
    },
    {
      "title": "asz",
      "description": "sd"
    }
  ],
  [
    {
      "title": "ws",
      "description": "sd"
    },
    {
      "title": "re",
      "description": "sd"
    }
  ],
  [
    {
      "title": "32",
      "description": "xxs"
    },
    {
      "title": "xxc",
      "description": "11"
    }
  ]
]
Run Code Online (Sandbox Code Playgroud)

上面的输入数组应该像下面的对象数组一样保存

[
  {
    "title": "asd",
    "description": "asd"
  },
  {
    "title": "asz",
    "description": "sd"
  },
  {
    "title": "ws",
    "description": "sd"
  },
  {
    "title": "re",
    "description": "sd"
  },
  {
    "title": "32",
    "description": "xxs"
  },
  {
    "title": "xxc",
    "description": "11"
  }
]
Run Code Online (Sandbox Code Playgroud)

我这样做如下,

const input=[[{"title":"asd","description":"asd"},{"title":"asz","description":"sd"}],[{"title":"ws","description":"sd"},{"title":"re","description":"sd"}],[{"title":"32","description":"xxs"},{"title":"xxc","description":"11"}]]
const output = [].concat(...input);
console.log(output);
Run Code Online (Sandbox Code Playgroud)

但我认为是在 ES6 中。你能帮我实现 ES5 吗?

提前致谢

Cer*_*nce 5

您可以apply将数组的输入数组concat

var input = [
  [
    {
      "title": "asd",
      "description": "asd"
    },
    {
      "title": "asz",
      "description": "sd"
    }
  ],
  [
    {
      "title": "ws",
      "description": "sd"
    },
    {
      "title": "re",
      "description": "sd"
    }
  ],
  [
    {
      "title": "32",
      "description": "xxs"
    },
    {
      "title": "xxc",
      "description": "11"
    }
  ]
];

var result = Array.prototype.concat.apply([], input);
console.log(result);
Run Code Online (Sandbox Code Playgroud)