当前位置:网站首页>JS flattened array of number shape structure
JS flattened array of number shape structure
2022-07-04 05:42:00 【_ Virgo programmer's daily life】
mounted() {
// It is known that JSON Data in tree structure data
let jsonData = [
{
id: 1, title: ' title 1', parent_id: 0, },
{
id: 2, title: ' title 2', parent_id: 0,
children: [
{
id: 3, title: ' title 2-1', parent_id: 2,
children: [
{
id: 4, title: ' title 3-1', parent_id: 3,
children: [
{
id: 5, title: ' title 4-1', parent_id: 4 }
]
}
]
},
{
id: 6, title: ' title 2-2', parent_id: 2 }
]
}
];
console.table(this.flat(jsonData));
}
//mounted in :
flat(data) {
return data.reduce((pre, cur) => {
// console.log(cur);
// The of the object is shown here children Properties and values are deconstructed in an empty array , Deconstruct other attributes and values of the object in i Inside .
const {
children = [], ...i } = cur; // Be careful ...i Can only be written at the end of the deconstruction assignment , Otherwise, the report will be wrong
// console.log(i);
// // console.log(children);
return pre.concat([{
...i }], this.flat(children)) // Using recursive callback , Array merge , Notice here {...i} It's deconstruction
}, []);
},
}
The results are as follows :
边栏推荐
- Ping port artifact psping
- 光模块字母含义及参数简称大全
- ansys命令
- 1.1 history of Statistics
- left_ and_ right_ Net normal version
- left_and_right_net正常版本
- BUU-Crypto-[GUET-CTF2019]BabyRSA
- 光模塊字母含義及參數簡稱大全
- BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述
- LM small programmable controller software (based on CoDeSys) note XXI: error 3703
猜你喜欢
企业级日志分析系统ELK(如果事与愿违那一定另有安排)
19.Frambuffer应用编程
One click filtering to select Baidu online disk files
Flask
SQL injection - injection based on MSSQL (SQL Server)
2022g2 power station boiler stoker special operation certificate examination question bank and answers
ping端口神器psping
Enterprise level log analysis system elk (if things backfire, there must be other arrangements)
C language simple student management system (including source code)
Simulink and Arduino serial port communication
随机推荐
Appearance of LabVIEW error dialog box
Viewing and using binary log of MySQL
Flask
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
Thread pool: use thread pool to optimize query speed
Redis realizes ranking function
1480. 一维数组的动态和
冲击继电器JC-7/11/DC110V
Unity2D--人物移动并转身
Simulink与Arduino串口通信
Flask
Solar insect killing system based on single chip microcomputer
Thinkphp6.0 middleware with limited access frequency think throttle
VB.net 简单的处理图片,黑白(类库——7)
left_and_right_net可解释性设计
Steady! Huawei micro certification Huawei cloud computing service practice is stable!
VB. Net calls ffmpeg to simply process video (class Library-6)
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
Input displays the currently selected picture
flink1.13 sql基础语法(二)join操作