国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

長治制作網(wǎng)站傳統(tǒng)營銷和網(wǎng)絡營銷的區(qū)別

長治制作網(wǎng)站,傳統(tǒng)營銷和網(wǎng)絡營銷的區(qū)別,寧波建工工程集團有限公司,做網(wǎng)站前景怎樣數(shù)組去重有許多種方法,下面列舉幾種常見方法 數(shù)組去重數(shù)組對象去重 數(shù)組去重 使用 Set:將數(shù)組轉(zhuǎn)化為 Set 對象,去重后再轉(zhuǎn)化回數(shù)組,Set 會自動去重 const arr [1, 2, 3, 2, 1, 4] const newArr [...new Set(arr)] console.log…

數(shù)組去重有許多種方法,下面列舉幾種常見方法

    • 數(shù)組去重
    • 數(shù)組對象去重

數(shù)組去重

  1. 使用 Set:將數(shù)組轉(zhuǎn)化為 Set 對象,去重后再轉(zhuǎn)化回數(shù)組,Set 會自動去重
const arr = [1, 2, 3, 2, 1, 4]
const newArr = [...new Set(arr)]
console.log(newArr) // [1, 2, 3, 4]
  1. 使用 filter:遍歷數(shù)組,對每個元素判斷是否在新數(shù)組中出現(xiàn)過。
const arr = [1, 2, 3, 2, 1, 4]
const newArr= arr.filter((item, index) => {return arr.indexOf(item) === index
})
console.log(newArr) // [1, 2, 3, 4]
  1. 使用 reduce:遍歷數(shù)組,對每個元素判斷是否在新數(shù)組中出現(xiàn)過,如果沒有則將其添加到新數(shù)組中。
const arr = [1, 2, 3, 2, 1, 4]
const newArr= arr.reduce((acc, cur) => {if (!acc.includes(cur)) {acc.push(cur)}return acc
}, [])
console.log(newArr) // [1, 2, 3, 4]
  1. 使用 Map:遍歷數(shù)組,將每個元素作為 key 存儲到 Map 中,去重后再轉(zhuǎn)化回數(shù)組。
const arr = [1, 2, 3, 2, 1, 4]
const map = new Map()
arr.forEach((item) => {map.set(item, true)
})
const newArr= Array.from(map.keys())
console.log(newArr) // [1, 2, 3, 4]

需要注意的是,以上方法都無法去重包含對象、數(shù)組等引用類型的元素的數(shù)組,需要使用其他方法實現(xiàn)。另外,以上方法去重后的數(shù)組順序可能與原數(shù)組不同,如果需要保持順序可以使用其他方法,比如通過遍歷原數(shù)組將不重復的元素依次添加到新數(shù)組的尾部。

數(shù)組對象去重

  1. 使用 Set :Set 是 ES6 中新增的一種數(shù)據(jù)結(jié)構(gòu),它類似于數(shù)組,但是成員的值都是唯一的,可以用來去重。我們可以使用 Set 來去重數(shù)組對象,然后再將結(jié)果轉(zhuǎn)換為數(shù)組。
const arr = [{ id: 1, name: 'AAAA' },{ id: 2, name: 'BBBB' },{ id: 1, name: 'AAAA' },{ id: 3, name: 'CCCC' }
];const result = Array.from(new Set(arr.map(JSON.stringify)), JSON.parse);
console.log(result); // [{ id: 1, name: 'AAAA' }, { id: 2, name: 'BBBB' }, { id: 3, name: 'CCCC' }]
  1. 使用 reduce :我們也可以使用 reduce 方法進行去重,具體步驟如下:
    · 遍歷數(shù)組中的每一個元素;
    · 對于每一個元素,判斷它是否已經(jīng)出現(xiàn)過(使用 Array.prototype.findIndex() 判斷);
    · 如果沒有出現(xiàn)過,就將它添加到結(jié)果數(shù)組中;
const arr = [{ id: 1, name: 'AAAA' },{ id: 2, name: 'BBBB' },{ id: 1, name: 'AAAA' },{ id: 3, name: 'CCCC' }
]const result = arr.reduce((acc, curr) => {const index = acc.findIndex((item) => item.id === curr.id)if (index < 0) {acc.push(curr)}return acc
}, [])console.log(result) // [{ id: 1, name: 'AAAA' }, { id: 2, name: 'BBBB' }, { id: 3, name: 'CCCC' }]
  1. 使用 Map : Map 也可以用來去重數(shù)組對象,具體步驟如下:
    · 遍歷數(shù)組中的每一個元素;
    · 對于每一個元素,判斷它是否已經(jīng)出現(xiàn)過(使用 Map.has() 判斷);
    · 如果沒有出現(xiàn)過,就將它添加到結(jié)果數(shù)組中;
const arr = [{ id: 1, name: 'AAAA' },{ id: 2, name: 'BBBB' },{ id: 1, name: 'AAAA' },{ id: 3, name: 'CCCC' }
]const map = new Map()
const result = []for (const item of arr) {if (!map.has(item.id)) {map.set(item.id, true)result.push(item)}
}console.log(result) // [{ id: 1, name: 'AAAA' }, { id: 2, name: 'BBBB' }, { id: 3, name: 'CCCC' }]
http://aloenet.com.cn/news/36146.html

相關文章:

  • ui設計與網(wǎng)站建設網(wǎng)絡推廣渠道都有哪些
  • 網(wǎng)站一個人可以做嗎找培訓機構(gòu)的網(wǎng)站
  • 網(wǎng)站建設技術(shù)分類aso具體優(yōu)化
  • 做中介開什么網(wǎng)站如何搜索網(wǎng)頁關鍵詞
  • 湖北網(wǎng)站建設企業(yè)百度sem推廣具體做什么
  • 富平做網(wǎng)站中國職業(yè)培訓在線平臺
  • 網(wǎng)站設計創(chuàng)意2023年6月疫情情況
  • 做ppt好用的網(wǎng)站廣告代發(fā)平臺
  • wen前端網(wǎng)站開發(fā)日記外鏈的作用
  • 清遠企業(yè)網(wǎng)站排名win7優(yōu)化教程
  • 權(quán)重較高網(wǎng)站深圳百度推廣聯(lián)系方式
  • 專注大連網(wǎng)站建設百度推廣登錄手機版
  • asp.net 網(wǎng)站訪問量商品推廣與營銷的方式
  • 京東商城網(wǎng)站設計酒店如何進行網(wǎng)絡營銷
  • 畫冊制作揭陽seo推廣公司
  • 永嘉網(wǎng)站建設幾熱門關鍵詞
  • 山東美建站金華百度推廣公司
  • 開發(fā)一個視頻網(wǎng)站要多少錢360優(yōu)化大師app下載
  • 南城區(qū)網(wǎng)站仿做網(wǎng)絡營銷推廣與策劃
  • 05網(wǎng)亮點給力大試卷網(wǎng)站seo博客
  • 贛州信息港贛州熱線湖南seo網(wǎng)站多少錢
  • 我的世界做神器指令網(wǎng)站網(wǎng)絡平臺建站
  • 網(wǎng)站開發(fā)難學嗎今天的新聞 聯(lián)播最新消息
  • 用vs2010做的網(wǎng)站網(wǎng)頁設計模板圖片
  • 陽信做網(wǎng)站營銷型網(wǎng)站建設費用
  • 昆明做網(wǎng)站的個人淘寶seo搜索引擎原理
  • 南陽做網(wǎng)站百度搜索引擎排名規(guī)則
  • 公司網(wǎng)站開發(fā)交接注意事項seo研究中心怎么了
  • 做網(wǎng)站網(wǎng)絡seo優(yōu)化教程自學
  • wordpress 獲取根目錄上海seo網(wǎng)站推廣公司