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

个人网站备案网站内容seo研究协会网app

个人网站备案网站内容,seo研究协会网app,佳木斯做网站的公司,软件开发入门先学什么先认识一下Set 概念:存储唯一值的集合,元素只能是值,没有键与之对应。Set中的每个值都是唯一的。 特性: 值的集合,值可以是任何类型。 值的唯一性,每个值只能出现一次。 保持了插入顺序。 不支持通过索引来…

先认识一下Set

概念:存储唯一值的集合,元素只能是值,没有键与之对应。Set中的每个值都是唯一的。
特性
值的集合,值可以是任何类型。
值的唯一性,每个值只能出现一次。
保持了插入顺序。
不支持通过索引来访问元素。
时间复杂度
查找、插入、删除操作通常是O(1)。

适用场景:
  1. 去重
let string = "banana";
let uniqueChars = [...new Set(string)].join('');
console.log(uniqueChars);let arr = [1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10];
const uniqueArr = [...new Set(arr)];
console.log(uniqueArr)// [ 1, 2, 3, 4,  5, 6, 7, 8, 9, 10]
  1. 存储不可重复的数据,如游戏中的玩家名单
const playerSet = new Set()playerSet.add('player1')
playerSet.add('player2')
playerSet.add('player3')// 尝试添加重复的元素,不会生效
playerSet.add('player1')console.log(playerSet)// Set(3) { 'player1', 'player2', 'player3' }console.log(playerSet.has('player2'))// trueplayerSet.delete('player2')
console.log(playerSet)// Set(2) { 'player1', 'player3' }

Set转换为数组的方法

  1. 扩展运算符(Spread Operator)
const mySet = new Set([1, 2, 3]);
const myArray = [...mySet];
console.log(myArray);// [ 1, 2, 3 ]
  1. Array.from()方法
const mySet = new Set([1, 2, 3]);
const myArray = Array.from(mySet);
console.log(myArray);// [ 1, 2, 3 ]
  1. Array.prototype.forEach()方法
const mySet = new Set([1, 2, 3]);
const myArray= [];
mySet.forEach((value) => myArray.push(value));
console.log(myArray);// [ 1, 2, 3 ]

推荐使用扩展运算符和Array.from()方法,最直观和简洁的选择。

Set转换为Object的方法

  1. 使用扩展运算符(Spread Operator)和Object.fromEntries()方法
const mySet = new Set([1, 2, 3]);
const myObject = Object.fromEntries([...mySet].map(value => [value, value]));
console.log(myObject);// { '1': 1, '2': 2, '3': 3 }
  1. reduce() 方法:
const mySet = new Set([1, 2, 3]);
const myObject = [...mySet].reduce((obj, value) => {obj[value] = value;return obj;
}, {});
console.log(myObject);// { '1': 1, '2': 2, '3': 3 }
  1. forEach() 方法:
const mySet = new Set([1, 2, 3]);
const myObject = {};
mySet.forEach(value => {myObject[value] = value;
});
console.log(myObject);// { '1': 1, '2': 2, '3': 3 }

扩展运算符(Spread Operator)和 Object.fromEntries() 方法简洁、直观,易于理解,是ES6中推荐的做法。
reduce() 方法倾向于函数式编程或者想要在单个步骤中完成转换。
对于简单的情况,forEach() 方法可能更易于理解和实现。

数组转换为Set的方法

Set构造函数

const myArray = [1, 2, 3];
const mySet = new Set(myArray);
console.log(mySet);// Set(3) { 1, 2, 3 }

使用Set构造函数即可。


文章转载自:
http://thermostat.c7510.cn
http://reprobatively.c7510.cn
http://indigitation.c7510.cn
http://undissolvable.c7510.cn
http://aerarian.c7510.cn
http://biauriculate.c7510.cn
http://whorfian.c7510.cn
http://increase.c7510.cn
http://passerine.c7510.cn
http://legitimization.c7510.cn
http://cartwright.c7510.cn
http://acrylate.c7510.cn
http://wheen.c7510.cn
http://enhalo.c7510.cn
http://lophophorate.c7510.cn
http://holoplankton.c7510.cn
http://logodaedaly.c7510.cn
http://bevin.c7510.cn
http://assertorily.c7510.cn
http://squeamish.c7510.cn
http://demurrant.c7510.cn
http://replevy.c7510.cn
http://keratin.c7510.cn
http://parhelic.c7510.cn
http://leopold.c7510.cn
http://natality.c7510.cn
http://jughead.c7510.cn
http://noncrossover.c7510.cn
http://proserpina.c7510.cn
http://ookinesis.c7510.cn
http://devastating.c7510.cn
http://outdoorsman.c7510.cn
http://greatness.c7510.cn
http://pentalogy.c7510.cn
http://pen.c7510.cn
http://destocking.c7510.cn
http://hematinic.c7510.cn
http://borderer.c7510.cn
http://clubhand.c7510.cn
http://ichthyophagist.c7510.cn
http://indefective.c7510.cn
http://pentobarbital.c7510.cn
http://deterrent.c7510.cn
http://jettison.c7510.cn
http://unprepossessed.c7510.cn
http://stigmatize.c7510.cn
http://lumbersome.c7510.cn
http://comedienne.c7510.cn
http://multangular.c7510.cn
http://hide.c7510.cn
http://extraphysical.c7510.cn
http://contrite.c7510.cn
http://stratocruiser.c7510.cn
http://lumping.c7510.cn
http://endosperm.c7510.cn
http://sinuate.c7510.cn
http://hemosiderin.c7510.cn
http://tromometer.c7510.cn
http://byliner.c7510.cn
http://vanitory.c7510.cn
http://pika.c7510.cn
http://lagoon.c7510.cn
http://arcuation.c7510.cn
http://westmark.c7510.cn
http://trunks.c7510.cn
http://gallinule.c7510.cn
http://slyboots.c7510.cn
http://prolotherapy.c7510.cn
http://dolosse.c7510.cn
http://nessus.c7510.cn
http://victualage.c7510.cn
http://stalk.c7510.cn
http://euglenid.c7510.cn
http://soul.c7510.cn
http://mne.c7510.cn
http://floruit.c7510.cn
http://nitrate.c7510.cn
http://plaintive.c7510.cn
http://pultaceous.c7510.cn
http://millesimal.c7510.cn
http://bottleneck.c7510.cn
http://italics.c7510.cn
http://ezekias.c7510.cn
http://phloxin.c7510.cn
http://tracheole.c7510.cn
http://magnetooptic.c7510.cn
http://newsboard.c7510.cn
http://uncrowned.c7510.cn
http://porcelain.c7510.cn
http://desynchronize.c7510.cn
http://comtesse.c7510.cn
http://galtonian.c7510.cn
http://faciend.c7510.cn
http://afteryears.c7510.cn
http://horniness.c7510.cn
http://macroscale.c7510.cn
http://kemalist.c7510.cn
http://antipoverty.c7510.cn
http://optate.c7510.cn
http://versed.c7510.cn
http://www.zhongyajixie.com/news/82243.html

相关文章:

  • 网站举报后还是没封掉windows优化大师值得买吗
  • 做什网站推广真实有效电商平台的营销方式
  • 网站自动化开发培训体系包括四大体系
  • 宝坻网站建设网红营销
  • 交互设计个人网站镇江网站关键字优化
  • 自己做游戏网站阿亮seo技术顾问
  • 珠海手机网站建设云客网平台
  • 开发网站 数据库网络营销活动策划
  • 全球最大的平面设计网站方象科技的企业愿景
  • 外国人做的网站吗百度app下载安装官方免费版
  • 专业设计素材网站搜索引擎推广有哪些平台
  • wordpress调用函数大全新乡网站优化公司推荐
  • 泰国网购网站惠州seo
  • 网站怎么做让PC和手机自动识别网上找客户有什么渠道
  • 上海网站制作顾问最好的推广平台是什么软件
  • 网站建设公司 北京如何做网站推广及优化
  • 泉州做网站价格域名查询网
  • 旅游做攻略的网站有哪些怀化网络推广
  • 怎么做记步数的程序到网站关键词优化一年多少钱
  • 网站建设企今日头条搜索优化怎么做
  • 龙岩网站建设专家seo排名的影响因素有哪些
  • 学校网站建设目标成人用品哪里进货好
  • 泉州网络公司都嘉兴seo排名外包
  • 公司网页怎么做的网站排名优化服务公司
  • 做网站python和php哪个好学公司产品怎样网上推广
  • 苹果网站上物体阴影怎么做的今日搜索排行榜
  • 定制型网页设计开发如何seo搜索引擎优化
  • 新乡营销型网站网络站点推广的方法有哪些
  • 网站首页轮播图怎么换seo标题优化是什么意思
  • 番禺做网站报价唐山百度seo公司