加载中...
PAGE

js 实现数组去重,数组扁平化

Post on 2021-10-27 9 0

数组去重实现

let person = [ {id: 0, name: "小明"}, {id: 1, name: "小张"}, {id: 2, name: "小李"}, {id: 3, name: "小孙"}, {id: 1, name: "小周"}, {id: 2, name: "小陈"}, ]; let obj = {}; person = person.reduce((cur,next)=>{ if(!obj[next.id]){ cur.push(next) obj[next.id]=next } return cur },[]) console.log(person)

image

数组扁平化实现

var arrs = [1,2,3,[4],[5,6,[7]]] function flat(arr){ let arrs = [] arr.forEach(i=>{i instanceof Array?arrs=arrs.concat(flat(i)):arrs.push(i)}) return arrs } console.log(flat(arrs))

images

mysql 树目录查询语句优化,提高查询效率

mysql 树目录查询语句优化,提高查询效率

阅读更多
js 实现简易版深拷贝

js 实现简易版深拷贝

阅读更多
mysql FROM多表时同时做为left join参数时报错

mysql FROM多表时同时做为left join参数时报错

阅读更多

暂无评论

    发表评论
    返回顶部
    X