Мне нужно объединить кусок массивов в один массив с массивом объектов в 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"
}
]
]
Вышеупомянутый входной массив должен быть сохранен как массив объектов, как показано ниже.
[
{
"title": "asd",
"description": "asd"
},
{
"title": "asz",
"description": "sd"
},
{
"title": "ws",
"description": "sd"
},
{
"title": "re",
"description": "sd"
},
{
"title": "32",
"description": "xxs"
},
{
"title": "xxc",
"description": "11"
}
]
Пожалуйста, подскажите, как я могу этого добиться.
Заранее большое спасибо
Нет .. это может отличаться



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Вы можете использовать .reduce() и .concat().
let data = [[{"title": "asd","description": "asd"},{"title": "asz","description": "sd"}],[{"title": "ws","description": "sd"},{"title": "re","description": "sd"}],[{"title": "32","description": "xxs"},{"title": "xxc","description": "11"}]];
let result = data.reduce((a, c) => a.concat(c), []);
console.info(result);Вы можете использовать concat() и оператор распространения (...):
var arr = [
[
{
"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 res = [].concat(...arr);
console.info(res);Вы просто ищете способ плоской карты, который легко с concat и распространяется:
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.info(output);
количество массивов фиксировано?