当前位置:网站首页>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 :
边栏推荐
- How to configure static IP for Kali virtual machine
- BUU-Pwn-test_ your_ nc
- Letter meaning and parameter abbreviation of optical module Daquan
- SQL injection - injection based on MSSQL (SQL Server)
- [QT] create mycombobox click event
- Simulink与Arduino串口通信
- VB. Net simple processing pictures, black and white (class library - 7)
- Penetration tool - sqlmap
- Wechat applet +php realizes authorized login
- 冲击继电器JC-7/11/DC110V
猜你喜欢
Upper computer software development - log information is stored in the database based on log4net
js arguments参数使用和详解
Google Chrome browser will support the function of selecting text translation
光模塊字母含義及參數簡稱大全
C语言简易学生管理系统(含源码)
Simulink and Arduino serial port communication
Just do it with your hands 7 - * project construction details 2 - hook configuration
2022 R2 mobile pressure vessel filling retraining question bank and answers
补某视频网站的js,进行视频解密
Kubernets first meeting
随机推荐
VB. Net simple processing pictures, black and white (class library - 7)
JS string splicing enhancement
Supplement the JS of a video website to decrypt the video
VB.net 调用FFmpeg简单处理视频(类库——6)
Basic concept of bus
How to clone objects
2022年R2移动式压力容器充装复训题库及答案
tutle时钟改进版
Character types of C language
2022 t elevator repair operation certificate examination question bank and simulation examination
One click filtering to select Baidu online disk files
Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
JS扁平化数形结构的数组
left_ and_ right_ Net normal version
fastjson
如何获取el-tree中所有节点的父节点
Flink1.13 SQL basic syntax (I) DDL, DML
Arc135 a (time complexity analysis)
Input displays the currently selected picture
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)