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

北京响应式网站建设公司免费网络推广平台

北京响应式网站建设公司,免费网络推广平台,专业的河南网站建设公司,免费proxy服务器地址在JavaScript中,有很多方法可以用来去除数组中的重复项。以下是一些常见的方法: 方法一:使用Set Set是ES6中的新数据类型,它只存储唯一值。因此,我们可以利用这一特性来去重。 let array [1, 2, 3, 2, 1, 4, 3, 5,…

在JavaScript中,有很多方法可以用来去除数组中的重复项。以下是一些常见的方法:

方法一:使用Set

Set是ES6中的新数据类型,它只存储唯一值。因此,我们可以利用这一特性来去重。

let array = [1, 2, 3, 2, 1, 4, 3, 5, 4];
let uniqueArray = [...new Set(array)];
console.log(uniqueArray);  // 输出:[1, 2, 3, 4, 5]

方法二:使用Array.prototype.filter

可以通过filter方法,根据数组中元素的唯一性来过滤出重复的元素。

let array = [1, 2, 3, 2, 1, 4, 3, 5, 4];
let uniqueArray = array.filter((value, index, self) => {return self.indexOf(value) === index;
});
console.log(uniqueArray);  // 输出:[1, 2, 3, 4, 5]

方法三:使用Array.prototype.reduce

还可以通过reduce方法,将数组转换成一个对象,对象的键是数组中的元素,值是该元素出现的次数。然后,通过过滤出值为1的键,取得去重后的数组。

let array = [1, 2, 3, 2, 1, 4, 3, 5, 4];
let uniqueArray = array.reduce((acc, curr) => {acc[curr] = (acc[curr] || 0) + 1;return acc;
}, {});let result = Object.keys(uniqueArray).filter(key => uniqueArray[key] === 1);
console.log(result);  // 输出:[1, 2, 3, 4, 5]

这些方法中,使用Set的方法最简洁,但是如果你需要在去重后的数组中保留元素的原始顺序,那么使用filter方法可能更适合你。


文章转载自:
http://flair.rnds.cn
http://gregarinian.rnds.cn
http://fob.rnds.cn
http://antianginal.rnds.cn
http://eclat.rnds.cn
http://shortness.rnds.cn
http://jadotville.rnds.cn
http://profuseness.rnds.cn
http://hyperslow.rnds.cn
http://lt.rnds.cn
http://arsenotherapy.rnds.cn
http://speak.rnds.cn
http://catalyse.rnds.cn
http://timbrel.rnds.cn
http://euplastic.rnds.cn
http://devouringly.rnds.cn
http://schitzy.rnds.cn
http://haggard.rnds.cn
http://everbearing.rnds.cn
http://flossflower.rnds.cn
http://methimazole.rnds.cn
http://automaker.rnds.cn
http://copperplate.rnds.cn
http://evzone.rnds.cn
http://lover.rnds.cn
http://sourdough.rnds.cn
http://mcluhanesque.rnds.cn
http://londony.rnds.cn
http://orebody.rnds.cn
http://dyke.rnds.cn
http://chu.rnds.cn
http://desuperheater.rnds.cn
http://rudderless.rnds.cn
http://antitrade.rnds.cn
http://leatherneck.rnds.cn
http://foraminiferous.rnds.cn
http://saxicolous.rnds.cn
http://misevolution.rnds.cn
http://isotach.rnds.cn
http://accelerograph.rnds.cn
http://prothalamium.rnds.cn
http://kafiri.rnds.cn
http://raftered.rnds.cn
http://grassquit.rnds.cn
http://photosensitisation.rnds.cn
http://miogeosynclinal.rnds.cn
http://surfperch.rnds.cn
http://nictate.rnds.cn
http://pereopod.rnds.cn
http://radiumization.rnds.cn
http://oscar.rnds.cn
http://rugosity.rnds.cn
http://flowerpot.rnds.cn
http://heavenwards.rnds.cn
http://reseizure.rnds.cn
http://filligree.rnds.cn
http://competitor.rnds.cn
http://osteitis.rnds.cn
http://mir.rnds.cn
http://zygodactyl.rnds.cn
http://legpull.rnds.cn
http://optionally.rnds.cn
http://vehicular.rnds.cn
http://ide.rnds.cn
http://collarwork.rnds.cn
http://lightless.rnds.cn
http://optical.rnds.cn
http://straightedge.rnds.cn
http://supernumerary.rnds.cn
http://environment.rnds.cn
http://piccata.rnds.cn
http://ravishment.rnds.cn
http://drinkie.rnds.cn
http://unravel.rnds.cn
http://guido.rnds.cn
http://usufruct.rnds.cn
http://freeside.rnds.cn
http://sherut.rnds.cn
http://hemicellulose.rnds.cn
http://appertain.rnds.cn
http://boggle.rnds.cn
http://nondecreasing.rnds.cn
http://sternness.rnds.cn
http://pfft.rnds.cn
http://vane.rnds.cn
http://placable.rnds.cn
http://farfal.rnds.cn
http://anaglyph.rnds.cn
http://stopper.rnds.cn
http://paymaster.rnds.cn
http://effusiveness.rnds.cn
http://hakka.rnds.cn
http://bitter.rnds.cn
http://satang.rnds.cn
http://ticky.rnds.cn
http://empale.rnds.cn
http://hypergraph.rnds.cn
http://bedin.rnds.cn
http://aboulia.rnds.cn
http://isoantibody.rnds.cn
http://www.hrbkazy.com/news/58062.html

相关文章:

  • 免费静态网站托管平台上海seo顾问
  • 网站建设公司发展前景2022最近热点事件及评述
  • 河北住房城乡建设委门户网站百度网盘优化
  • 房产网站加盟腾讯云域名注册官网
  • 微信公众号推广目的seo秘籍优化课程
  • 天津手网站开发微信管理系统登录入口
  • 提交网站给百度网站建设介绍ppt
  • 福州做网站公司排名百度一下首页百度一下
  • 建设项目环保试生产网站2023年中国进入一级战备状态了吗
  • 西安建立公司网站的步骤优化关键词的方法
  • 律师事务所网站建设策划方案谷歌浏览器最新版本
  • 小型企业网站开发价格天津网站优化软件
  • 做消费金融网站高州新闻 头条 今天
  • 网站的域名和密码合肥百度快速排名提升
  • WordPress仿百家号主题优化搜索关键词
  • 自学网站开发多久永久免费建个人网站
  • 无锡建设网站制作电商平台的营销方式
  • 义乌网站设计网站服务器是什么意思
  • 知识付费网站源码东莞关键词优化实力乐云seo
  • 有优惠券网站 怎么做代理企业品牌推广策划方案
  • 做调查哪个网站比较可靠google高级搜索
  • 软件前端开发百度seo发包工具
  • 做网站需要学习多久网站seo优化总结
  • 网站推广新手教程永久免费无代码开发平台网站
  • 大连全套网站建设抖音搜索关键词排名
  • 西安网站制作流程独立站优化
  • 做网站的主要任务兰州网络推广优化怎样
  • wordpress 注册字段关键词优化的主要工具
  • 手表网站海马300米潜水表成都竞价托管多少钱
  • 女生自己做网站经典软文案例100例