console.log(Object.is(+0,-0)) //false 但是控制台为true console.log(Object.is(NaN,NaN)) // true 但是控制台是false const uniqueArray = (arr)=>{ const result = [] outer:for(const item of arr){ for(r of result){ if(equals(r,item)){ continue outer } } result.push(item) } } function isPrimitive(value){ return value === null || (typeof value !== 'object' && typeof value !== 'function') } function equals(value1,value2){ if(isPrimitive(value1) && isPrimitive(value2)){ return Object.is(value1,value2) } const entries1 = Object.entries(value1) const entries2 = Object.entries(value2) if(entries1.length !== entries2.length){ return false } for(const [key,value] of entries1){ if(!equals(value,value2[key])){ return false } } }
标签:const,value1,Object,value,value2,数组,false,属性 From: https://www.cnblogs.com/MDGE/p/18573884