// 树形数组扁平化
const extractTree = (data: TagsParams[]) => {
if (!data.length) return [];
const list: TagsParams[] = [];
const getObj = (arr: TagsParams[]) => {
arr.forEach((row: TagsParams) => {
let obj = {};
obj = JSON.parse(JSON.stringify(row));
list.push(obj);
if (row.children) {
getObj(row.children);
}
});
return list;
};
return getObj(data);
};

  

js处理树形数组扁平化的更多相关文章

  1. js多维数组扁平化

    数组扁平化,就是将多维数组碾平为一维数组,方便使用. 一:例如,一个二维数组 var arr = ['a', ['b', 2], ['c', 3, 'x']],将其扁平化: 1.  通过 apply ...

  2. js中数组扁平化处理

  3. JavaScript数组常用方法解析和深层次js数组扁平化

    前言 数组作为在开发中常用的集合,除了for循环遍历以外,还有很多内置对象的方法,包括map,以及数组筛选元素filter等. 注:文章结尾处附深层次数组扁平化方法操作. 作为引用数据类型的一种,在处 ...

  4. JS: 数组扁平化

    数组扁平化 什么是数组扁平化? 数组扁平化就是将一个多层嵌套的数组 (Arrary) 转化为只有一层. // 多层嵌套 [1, 2, [3, 4]] // 一层 [1, 2, 3, 4] 递归实现 思 ...

  5. js技巧-使用reduce实现更简洁的数组对象去重和数组扁平化

    Array.prototype.reduce()方法介绍: 感性认识reduce累加器: const arr = [1, 2, 3, 4]; const reducer = (accumulator, ...

  6. JS数组专题1️⃣ ➖ 数组扁平化

    一.什么是数组扁平化 扁平化,顾名思义就是减少复杂性装饰,使其事物本身更简洁.简单,突出主题. 数组扁平化,对着上面意思套也知道了,就是将一个复杂的嵌套多层的数组,一层一层的转化为层级较少或者只有一层 ...

  7. js实现数组扁平化

    数组扁平化的方式 什么是数组扁平化? 数组扁平化:指将一个多维数组转化为一个一维数组. 例:将下面数组扁平化处理. const arr = [1, [2, 3, [4, 5]]] // ---> ...

  8. javascrip的数组扁平化

    扁平化 数组的扁平化,就是将一个嵌套多层的数组 array (嵌套可以是任何层数)转换为只有一层的数组. 举个例子,假设有个名为 flatten 的函数可以做到数组扁平化,效果就会如下: var ar ...

  9. js数组扁平化

    看到一个有趣的题目: var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]; 一个多维 ...

  10. JS数组扁平化(flat)

    需求:多维数组=>一维数组 let ary = [1, [2, [3, [4, 5]]], 6]; let str = JSON.stringify(ary); 第0种处理:直接的调用 arr_ ...

随机推荐

  1. URLDecoder.decode() 特殊字符的处理

    在网络get请求中,如果存在特殊字符 比如  "+,/,%,&,= " ,如果没有被转义就直接使用 发现 + 号 仍然是 + 号,初看上去是没什么问题  这样在我们在后台接 ...

  2. insert_base_x.txt

    insert into g_temp.test_basevalues('20220202'::date, 1, 'apple'),('20220203'::date, 5, 'banana'),('2 ...

  3. PyTorch Live get started from Windows

    〇. PyTorch Live https://pytorch.org/live/docs/tutorials/get-started-manually/ 以下 命令 建议都用 以管理员身份运行的 P ...

  4. c# reflect里面的getValue()参数

    Type ty = t.GetType(); PropertyInfo[] PropertyInfo = ty.GetProperties(); string Typename = typeof(T) ...

  5. VMWARE 虚拟机配置优化

    如果硬件性能不足,可做如下优化. 1.禁用 VMWARE  虚拟内存功能. 编辑->首选项-> 内存  , 设置如下,禁用内存交换. 2. 如果虚拟机装在机械盘,而电脑有固太硬盘,可通过 ...

  6. torch& tensorflow

    #torchimport torch import torch.nn as nn import torch.nn.functional as F class Net(nn.Module): def _ ...

  7. uniapp记录

    1.uniapp获取imei imsi 型号 厂商 https://blog.csdn.net/qq_35620498/article/details/112172115

  8. git log 的常用用法

    1.最基本的 git log 2.简化版本 git log --oneline 3. 作者筛选 4.时间筛选 git log --since="2022.05.26" --unti ...

  9. One-Shot Transfer Learning of Physics-Informed Neural Networks

    本文提出了一种将迁移学习应用到PINN的方法.可以极大的缩短训练PINN所用的时间,目前,PINN所需要的训练次数往往都在成千上万次, 作者通过批量训练PINN,来学习丰富的潜在空间用来执行迁移学习. ...

  10. Java DelayQueue包装类

    public class DelayQueueWrapper<T> { private TimeUnit timeUnit; private final Long capacity; pr ...