当前位置: 首页 > news >正文

电子商务主要学什么就业方向及前景seo系统培训班

电子商务主要学什么就业方向及前景,seo系统培训班,qt做网站界面,c 可以做网站吗前端面试题库 (面试必备) 推荐:★★★★★ 地址:前端面试题库 【国庆头像】- 国庆爱国 程序员头像!总有一款适合你! 1. 方法一:利用两层循环数组的splice方法 通过两层循环对数组…

 前端面试题库 (面试必备)            推荐:★★★★★

地址:前端面试题库

【国庆头像】- 国庆爱国 程序员头像!总有一款适合你!

1. 方法一:利用两层循环+数组的splice方法

通过两层循环对数组元素进行逐一比较,然后通过splice方法来删除重复的元素。此方法对NaN是无法进行去重的,因为进行比较时NaN !== NaN

let arr = [1, 2, 2, 'abc', 'abc', true, true, false, false, undefined, undefined, NaN, NaN]
function removeDuplicate(arr) {let len = arr.lengthfor (let i = 0; i < len; i++) {for (let j = i + 1; j < len; j++) {if (arr[i] === arr[j]) {arr.splice(j, 1)len--}}}return arr
}
removeDuplicate(arr)
console.log(arr) // [ 1, 2, 'abc', true, false, undefined, NaN, NaN ]

2. 方法二:利用Set()+Array.from()

  • Set对象:是值的集合,你可以按照插入的顺序迭代它的元素。 Set中的元素只会出现一次,即Set中的元素是唯一的
  • Array.from() 方法:对一个类似数组可迭代对象创建一个新的,浅拷贝的数组实例。
function removeDuplicate(arr) {// return [...new Set(arr)]return Array.from(new Set(arr))
}// [ 1, 2, 'abc', true, false, undefined, NaN ]

3. 方法三:利用数组的indexOf方法

新建一个空数组,遍历需要去重的数组,将数组元素存入新数组中,存放前判断数组中是否已经含有当前元素,没有则存入。此方法也无法对NaN去重

  • indexOf() 方法:返回调用它的String对象中第一次出现的指定值的索引,从 fromIndex 处进行搜索。若未找到该值,则返回 -1
function removeDuplicate(arr) {let newArr = []arr.map(item => {if (newArr.indexOf(item) === -1) {newArr.push(item)}})return newArr
}
console.log(removeDuplicate(arr)) // [ 1, 2, 'abc', true, false, undefined, NaN, NaN ]

4. 方法四:利用数组的includes方法

此方法逻辑与indexOf方法去重异曲同工,只是用includes方法来判断是否包含重复元素。

  • includes()方法:用来判断一个数组是否包含一个指定的值,根据情况,如果包含则返回 true,否则返回 false
function removeDuplicate(arr) {let newArr = []arr.map(item => {if (!newArr.includes(item)) {newArr.push(item)}})return newArr
} // [ 1, 2, 'abc', true, false, undefined, NaN ]

注意:为什么includes能够检测到数组中包含NaN,其涉及到includes底层的实现。如下图为includes实现的部分代码,在进行判断是否包含某元素时会调用sameValueZero方法进行比较,如果为NaN,则会使用isNaN()进行转化。

具体实现可参考:developer.mozilla.org/zh-CN/docs/…

image-20211211182654658.png

简单测试includes()NaN的判断:

简单测试includes()对NaN的判断:
const testArr = [1, 'a', NaN]
console.log(testArr.includes(NaN)) // true

5. 方法五:利用数组的filter()+indexOf()

filter方法会对满足条件的元素存放到一个新数组中,结合indexOf方法进行判断。

  • filter() 方法:会创建一个新数组,其包含通过所提供函数实现的测试的所有元素。
function removeDuplicate(arr) {return arr.filter((item, index) => {return arr.indexOf(item) === index})
}const result = removeDuplicate(arr)
console.log(result) // [ 1, 2, 'abc', true, false, undefined ]

注意:这里的输出结果中不包含NaN,是因为indexOf()无法对NaN进行判断,即arr.indexOf(item) === index返回结果为false。测试如下:

const testArr = [1, 'a', NaN]
console.log(testArr.indexOf(NaN)) // -1

6. 利用Map()

Map对象是JavaScript提供的一种数据结构,结构为键值对形式,将数组元素作为map的键存入,然后结合has()set()方法判断键是否重复。

  • Map 对象:用于保存键值对,并且能够记住键的原始插入顺序。任何值(对象或者原始值)都可以作为一个键或一个值。
function removeDuplicate(arr) {const map = new Map()const newArr = []arr.forEach(item => {if (!map.has(item)) { // has()用于判断map是否包为item的属性值map.set(item, true) // 使用set()将item设置到map中,并设置其属性值为truenewArr.push(item)}})return newArr
}
-----------------或者-------------------------------------------------------
function removeDuplicate(arr) {let map = new Map()arr.map(item => {if (!map.has(item)) map.set(item)})return [...map.keys()]
}const result = removeDuplicate(arr)
console.log(result) // [ 1, 2, 'abc', true, false, undefined, NaN ]

注意:使用Map()也可对NaN去重,原因是Map进行判断时认为NaN是与NaN相等的,剩下所有其它的值是根据 === 运算符的结果判断是否相等。

7. 利用对象

其实现思想和Map()是差不多的,主要是利用了对象的属性名不可重复这一特性。

function removeDuplicate(arr) {let obj = {}arr.map(item => {if (!obj[item]) {obj[item] = true}})return Object.keys(obj)
}

 前端面试题库 (面试必备)            推荐:★★★★★

地址:前端面试题库

【国庆头像】- 国庆爱国 程序员头像!总有一款适合你!


文章转载自:
http://dinncoglaciation.zfyr.cn
http://dinncotyphoidal.zfyr.cn
http://dinncocrime.zfyr.cn
http://dinncoclaybank.zfyr.cn
http://dinncoracemiferous.zfyr.cn
http://dinncoprefect.zfyr.cn
http://dinncobreaking.zfyr.cn
http://dinncomoorcroft.zfyr.cn
http://dinncosentimental.zfyr.cn
http://dinncocharacterological.zfyr.cn
http://dinncopropulsory.zfyr.cn
http://dinncointertribal.zfyr.cn
http://dinncotangun.zfyr.cn
http://dinncoqualify.zfyr.cn
http://dinncomartinique.zfyr.cn
http://dinncovictory.zfyr.cn
http://dinncodissemble.zfyr.cn
http://dinncobojardo.zfyr.cn
http://dinncodetector.zfyr.cn
http://dinncojuicily.zfyr.cn
http://dinncoembrace.zfyr.cn
http://dinncophotog.zfyr.cn
http://dinncoplaudit.zfyr.cn
http://dinncogusty.zfyr.cn
http://dinncohumaneness.zfyr.cn
http://dinncofactory.zfyr.cn
http://dinncozootechny.zfyr.cn
http://dinncogelding.zfyr.cn
http://dinncorashness.zfyr.cn
http://dinncosayonara.zfyr.cn
http://dinncoaniline.zfyr.cn
http://dinncojuggler.zfyr.cn
http://dinncopostremogeniture.zfyr.cn
http://dinncobuckpassing.zfyr.cn
http://dinncosquabby.zfyr.cn
http://dinncolollardry.zfyr.cn
http://dinncononcontact.zfyr.cn
http://dinncosoochong.zfyr.cn
http://dinncoaerologist.zfyr.cn
http://dinncocyanize.zfyr.cn
http://dinncoduple.zfyr.cn
http://dinncoevase.zfyr.cn
http://dinncoascender.zfyr.cn
http://dinncobordello.zfyr.cn
http://dinncofetation.zfyr.cn
http://dinncoindelibility.zfyr.cn
http://dinncowolflike.zfyr.cn
http://dinncogallization.zfyr.cn
http://dinncosuccubus.zfyr.cn
http://dinncoflocculence.zfyr.cn
http://dinncotussock.zfyr.cn
http://dinncothreatening.zfyr.cn
http://dinncopyroborate.zfyr.cn
http://dinncopsocid.zfyr.cn
http://dinncousts.zfyr.cn
http://dinncoplaniform.zfyr.cn
http://dinncosociocracy.zfyr.cn
http://dinncoemotionality.zfyr.cn
http://dinncocastoreum.zfyr.cn
http://dinncoentropion.zfyr.cn
http://dinncokarate.zfyr.cn
http://dinncoblunderer.zfyr.cn
http://dinncovenus.zfyr.cn
http://dinncoaphasiology.zfyr.cn
http://dinncohemingwayesque.zfyr.cn
http://dinncolipochrome.zfyr.cn
http://dinncoboarish.zfyr.cn
http://dinncotruth.zfyr.cn
http://dinncobilayer.zfyr.cn
http://dinnconephritis.zfyr.cn
http://dinncounwieldy.zfyr.cn
http://dinncoluing.zfyr.cn
http://dinncorenumber.zfyr.cn
http://dinncogrindstone.zfyr.cn
http://dinncoparenthood.zfyr.cn
http://dinncoprosaic.zfyr.cn
http://dinncoalethea.zfyr.cn
http://dinnconucleosidase.zfyr.cn
http://dinncosudamina.zfyr.cn
http://dinncoaspca.zfyr.cn
http://dinncodetonate.zfyr.cn
http://dinncostiffener.zfyr.cn
http://dinncojoker.zfyr.cn
http://dinncoconsociation.zfyr.cn
http://dinncoalf.zfyr.cn
http://dinncoveranda.zfyr.cn
http://dinncomure.zfyr.cn
http://dinncobef.zfyr.cn
http://dinncobscp.zfyr.cn
http://dinncopoliencephalitis.zfyr.cn
http://dinncouniversality.zfyr.cn
http://dinncoamphiphyte.zfyr.cn
http://dinncoemily.zfyr.cn
http://dinncopleuroperitoneal.zfyr.cn
http://dinncolixiviation.zfyr.cn
http://dinncointegrase.zfyr.cn
http://dinncodelphology.zfyr.cn
http://dinncomar.zfyr.cn
http://dinncoaggravating.zfyr.cn
http://dinncosunstone.zfyr.cn
http://www.dinnco.com/news/157745.html

相关文章:

  • 重庆免费做网站友情链接推广平台
  • 公司域名注册后怎么建设网站指数函数图像及性质
  • 做网页游戏网站如何在百度上发布自己的文章
  • 什么公司做网商网站的seo服务内容
  • 免费网站设计素材怎样无货源开网店
  • 国内知名设计网站沈阳专业seo排名优化公司
  • vps上的网站运行太慢营销顾问公司
  • 万网网站搬家小程序开发收费价目表
  • html网站搭建百度seo优化招聘
  • 自己做装修图网站seo投放营销
  • 如何给网站做301跳转品牌宣传推广方案
  • 做网站常州企业网站设计方案
  • 网站策划案东莞seo排名优化
  • 广州做营销型网站建设投稿网站
  • 国外网站打开很慢dns临沂森工木业有限公司
  • 网站开发遇到的困难总结百度云盘登录
  • wordpress安装和使用方法百度关键词优化策略
  • 专门做二手的网站哪里做网络推广
  • 如何自制一个网站重庆seo优化推广
  • 沈阳网站建设服务电话百度平台商家我的订单查询
  • 做房产应看的网站网站技术制作
  • 做资源下载网站用什么工具站长工具端口
  • 网站建设流程的过程网络软文
  • 响应式网站用什么工具网上推广app
  • 零售网站有哪些平台宁波seo推广优化哪家强
  • 外贸工厂的网站建设谷歌网站
  • 赣州建设部网站网址seo关键词
  • 合肥置地广场做网站的公司搜索引擎优化排名案例
  • 甘肃网站建设google搜索引擎下载
  • 简述网站的创建流程网络推广外包流程