liuzeyang

Results 2 comments of liuzeyang

感觉上边都没有考虑原数据,都是把原数组改变掉了。我这里用了比较简单的规律: function convert(list){ let arr = JSON.parse(JSON.stringify(list)); for(let i = list.length - 1; i >= 0 ;i--){ if(arr[i].parentId - 1 < 0){ continue; } if(arr[arr[i].parentId - 1].children){ arr[arr[i].parentId -1].children.push(arr[i]) }else{...

两种解法: 1. 利用settimeout 接受多个参数的方向,将Math.floor(Math.random() * 1000)作为第三个参数,第二参数可以设置为任意值。 function print(n){ setTimeout(() => { console.log(n); }, 1, Math.floor(Math.random() * 1000)); } for(var i = 0; i < 100; i++){ print(i); } 2.可以利用settimeout 第一个参数可以是function是立即执行或者一个执行函数。