醉菜鸟 2021-11-17 09:00:06

JS数组去重

/** 数组去重 
  * @param $param 
  * @returns {*[]} 
  */
function array_unique ($param = []) {    
    const result = [], json = {};    
    let len = $param.length;    
    for (let i = 0; i < len; i++){        
        if (!json[$param[i]]) {            
            json[$param[i]] = 1;            
            result.push($param[i]);       
        }   
    }    
    return result;
}
意见反馈