About the reduce function in javascript help

//数组的去重
    let arr = [1,2,3,4,5,1,3,7,2,1,3,4,8,5,5,7]
    newarr = arr.reduce((pre,curr,index,arr)=>{
    
    
       // debugger
        console.log(pre,curr)
        //console.log(typeof pre,typeof curr)
        if (curr in pre) console.log(curr+"已经包含在对象中了");
        else pre.push(curr)
        //pre.push(curr)
        return pre
    },[])
    console.log(arr)
    console.log(newarr)

The following is the output result, why is it unclean? ? I'm bald, please help me
Insert picture description here

Solve the reduce problem in ES6 through the following two blogs

The difference between in and includes

Guess you like

Origin blog.csdn.net/qq_44606064/article/details/109522604