当前位置:网站首页>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 :
边栏推荐
- Online shrimp music will be closed in January next year. Netizens call No
- Halcon image calibration enables subsequent image processing to become the same as the template image
- Integer type of C language
- 【雕爷学编程】Arduino动手做(105)---压电陶瓷振动模块
- LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
- Supplement the JS of a video website to decrypt the video
- transformer坑了多少算力
- VB.net 简单的处理图片,黑白(类库——7)
- tutle时钟改进版
- Introduction To AMBA 简单理解
猜你喜欢

ANSYS command
![[Excel] 数据透视图](/img/45/be87e4428a1d8ef66ef34a63d12fd4.png)
[Excel] 数据透视图
![How to use postman to realize simple interface Association [add, delete, modify and query]](/img/e9/bf89eacdebcf2ec84c8a08c28b9ca8.png)
How to use postman to realize simple interface Association [add, delete, modify and query]

光模块字母含义及参数简称大全

Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology

Letter meaning and parameter abbreviation of optical module Daquan

Ping port artifact psping

input显示当前选择的图片

Penetration tool - sqlmap

光模塊字母含義及參數簡稱大全
随机推荐
BUU-Pwn-test_ your_ nc
Take you to quickly learn how to use qsort and simulate qsort
One click filtering to select Baidu online disk files
【微服务】Nacos集群搭建以及加载文件配置
ping端口神器psping
2022 t elevator repair operation certificate examination question bank and simulation examination
Wechat applet +php realizes authorized login
Arc135 a (time complexity analysis)
企业级日志分析系统ELK(如果事与愿违那一定另有安排)
Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
tutle时钟改进版
Steady! Huawei micro certification Huawei cloud computing service practice is stable!
left_ and_ right_ Net interpretable design
[paper summary] zero shot semantic segmentation
JS string splicing enhancement
BUU-Crypto-[HDCTF2019]basic rsa
19. Framebuffer application programming
BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述
Appearance of LabVIEW error dialog box
[QT] create mycombobox click event