加载中...
PAGE

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

Post on 2021-10-27 102 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

js 常用属性和方法等知识汇总

js 常用属性和方法等知识汇总

阅读更多
mysql INSERT SELECT FROM 语句的使用

mysql INSERT SELECT FROM 语句的使用

阅读更多
js 获取音乐的音频音谱

js 获取音乐的音频音谱

阅读更多

暂无评论

    发表评论
    返回顶部
    X