数组简单递归

news/2024/7/19 15:58:13 标签: js

数组简单递归

js">var data1 = [{
    "uid_step": "1",
    "step_to": [{
            "uid_step": "2",
            "step_to": [{
                "uid_step": "6",
                "step_to": null
            }]
        },
        {
            "uid_step": "3",
            "step_to": [{
                "uid_step": "6",
                "step_to": null
            }]
        },
        {
            "uid_step": "4",
            "step_to": [{
                "uid_step": "6",
                "step_to": null
            }]
        },
        {
            "uid_step": "5",
            "step_to": [{
                "uid_step": "6",
                "step_to": null
            }]
        }
    ]
}]
js">function diGUi(data1) {
    let tempArr1 = [];
    let tempArr2 = []
    for (let i = 0; i < data1.length; i++) {
        tempArr1.push(data1[i].uid_step);
        if (data1[i].step_to) {
            tempArr2 = diGUi(data1[i].step_to)
            tempArr1.push(tempArr2)
        }
    }
    return tempArr1;
}
console.log(diGUi(data1))
// [ '1',[ '2', [ '6' ], '3', [ '6' ], '4', [ '6' ], '5', [ '6' ] ] ]

http://www.niftyadmin.cn/n/1769520.html

相关文章

【探究】MatLab对于方程的求解

问题提出&#xff08;答案在最后以图片形式呈现&#xff09; 对于任意的一元方程&#xff0c;如何求解&#xff0c;在日常生活中,通常使用计算器的solve键直接求解&#xff0c;但是实际情况是当你用拿在手上的计算器去计算如下的方程时&#xff1a; 1/x1/(x0.05)1/(x0.1)1/(x…

函数加new与不加new区别

没有设置返回值 function fruit(type) {this.type type;console.log("this", this); } let fruit1 new fruit("apple"); // fruit {type: "apple"} let fruit2 fruit("apple"); //windowconsole.log(fruit1, fruit1) //fruit {typ…

【每日一坑】Java 父类与子类(1)

下列程序执行的结果应该是 &#xff08; &#xff09; a.Son Son B b.Base Son B c. 编译错误 class Base{public void method() {System.out.println("Base");} } class Son extends Base{public void method() {System.out.println("son");}public stat…

js原生自定义事件

html <button id"btn">按钮</button> <div id"m"></div> <div id"n"></div>Event 无参数传递 let btn document.getElementById("btn");let m document.getElementById("m");let n …

随机生成浮点数数组,随机生成一个数,看这个数组是否包含这个数

package test1025;import java.math.BigDecimal; //目标功能&#xff0c;随机生成10000个数&#xff0c;再随机生成一个数&#xff0c;若这一个数能在10000个数找到&#xff0c;返回这个数&#xff0c;若不能找到&#xff0c;则打印“没找到” public class Solution {public s…

call apply bind 改变this 指向问题

call方法 function info(name, age) {this.name name;this.age age;}function people(name, age, work) {info.call(this, name, age);console.log("他叫" this.name "," this.age "岁,职业是" work)}people("Li", 21, "I…

通过王者自走棋学操作系统-死锁产生的4个条件

前言 最近打王者自走棋&#xff0c;老是拿不了第一&#xff0c;我也太难了&#xff0c;特别每次都拿第二&#xff0c;都会被对面嘲讽一波&#xff0c;“打得很好”&#xff0c;这就导致了没有能够好好听课&#xff0c;所以还是好好学习吧&#xff08;笑&#xff09;&#xff0…

vue 插槽的简单使用

具名插槽与默认插槽的使用 父组件 <template><div>oindex<oIndex2><h1 slot"n1">内容1</h1><h2 slot"n2">内容1</h2><h3>内容3</h3></oIndex2></div> </template><script&g…