且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

RxJ将对象数组移动到根数组

更新时间:2023-11-20 15:55:28

基于图像,您有一个对象数组和一个数组.您可以使用[].concat(...data)将其展平.结合使用array#concat和扩展语法.

Based on the image, you have an array of objects and array. You can flatten it using [].concat(...data). Use array#concat with spread syntax.

var data = [{id: "12321", itemName: "Item 1", category: "All"}, [{id: "423423", itemName: "Sub Item 1", category: "subcat"}, {id: "413212", itemName: "Sub Item 2", category: "subcat"}],{id: "65655", itemName: "Item 2", category: "All"}, {id:"87877", itemName: "Item 3", category: "All"}, [{id: "354345", itemName: "Sub Item 1", category: "subcat"}, {id: "123434", itemName: "Sub Item 2", category: "subcat"}, {id: "765767", itemName: "Sub Item 3", category: "subcat"}, {id: "854643",itemName: "Sub Item 4", category: "subcat"}]],
    result = [].concat(...data);
console.log(result);