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

上海网站建设沪icp备seo赚钱吗

上海网站建设沪icp备,seo赚钱吗,长沙网站建设王道下拉惠,花色直播怎么看文章目录 1 实现数组的扁平化1.1 递归1.2 reduce1.3 扩展运算符1.4 split和toString1.5 flat1.6 正则表达式和JSON 1 实现数组的扁平化 1.1 递归 通过循环递归的方式,遍历数组的每一项,如果该项还是一个数组,那么就继续递归遍历&#xff0c…

文章目录

  • 1 实现数组的扁平化
    • 1.1 递归
    • 1.2 reduce
    • 1.3 扩展运算符
    • 1.4 split和toString
    • 1.5 flat
    • 1.6 正则表达式和JSON

1 实现数组的扁平化

1.1 递归

通过循环递归的方式,遍历数组的每一项,如果该项还是一个数组,那么就继续递归遍历,实现数组的每一项的连接。

let arr = [1, [2, [3, 4, 5]]];function flatten(arr) {let result = [];for (let i = 0; i < arr.length; i++) {if (Array.isArray(arr[i])) {result = result.concat(flatten(arr[i]));} else {result.push(arr[i]);}}return result;
}
flatten(arr);

1.2 reduce

简化第1种方法的代码,用reduce()来实现数组的拼接。

function flatten(arr) {return arr.reduce(function(prev, next) {return prev.concat(Array.isArray(next) ? flatten(next) : next);}, []);
}

1.3 扩展运算符

扩展运算符和some()的方法共同使用,逐层展开数组。

function flatten(arr) {while (arr.some(item => Array.isArray(item))) {arr = [].concat(...arr);}return arr;
}

1.4 split和toString

先用toString()将数组转换成用逗号分隔的字符串,然后再用split()方法把字符串重新转换为数组。

function flatten(arr) {return arr.toString().split(',');
}

1.5 flat

ES6中flat方法的语法:arr.flat([depth])

其中depth是可以传递数组的展开深度,默认是1,即展开1层数组。

如果层数不确定,参数可以传进Infinity,代表不论多少层都要展开。

function flatten(arr) {return arr.flat(Infinity);
}

1.6 正则表达式和JSON

先用JSON.stringify()的方法将数组转换为字符串,然后通过正则表达式过滤掉字符串中的数组的方括号,最后再利用JSON.parse()把它转换成数组。

function flatten(arr) {let str = JSON.stringify(arr);str = str.replace(/(\[|\])/g, '');str = '[' + str + ']';return JSON.parse(str);
}

文章转载自:
http://sire.c7498.cn
http://kimberley.c7498.cn
http://emetin.c7498.cn
http://doubled.c7498.cn
http://spade.c7498.cn
http://calisthenics.c7498.cn
http://fustigate.c7498.cn
http://explanatory.c7498.cn
http://commutability.c7498.cn
http://philanthropism.c7498.cn
http://safekeep.c7498.cn
http://kinemometer.c7498.cn
http://rickettsial.c7498.cn
http://somaplasm.c7498.cn
http://syndeton.c7498.cn
http://reverently.c7498.cn
http://discretionarily.c7498.cn
http://galliwasp.c7498.cn
http://velskoon.c7498.cn
http://latten.c7498.cn
http://superannuation.c7498.cn
http://millage.c7498.cn
http://nopalry.c7498.cn
http://eucharist.c7498.cn
http://playgirl.c7498.cn
http://saponification.c7498.cn
http://zymolysis.c7498.cn
http://disapprobation.c7498.cn
http://exit.c7498.cn
http://fissirostral.c7498.cn
http://righteously.c7498.cn
http://ruffianlike.c7498.cn
http://pulpit.c7498.cn
http://subsaline.c7498.cn
http://bedad.c7498.cn
http://important.c7498.cn
http://emperorship.c7498.cn
http://week.c7498.cn
http://aweather.c7498.cn
http://suds.c7498.cn
http://termless.c7498.cn
http://clamlike.c7498.cn
http://xenophile.c7498.cn
http://considerably.c7498.cn
http://overdelicate.c7498.cn
http://pentastylos.c7498.cn
http://undimmed.c7498.cn
http://queening.c7498.cn
http://ultrafiltrate.c7498.cn
http://pantheon.c7498.cn
http://kisan.c7498.cn
http://activize.c7498.cn
http://garuda.c7498.cn
http://incommutable.c7498.cn
http://routinization.c7498.cn
http://brewster.c7498.cn
http://coeliac.c7498.cn
http://cybernatic.c7498.cn
http://dominical.c7498.cn
http://bah.c7498.cn
http://ribbonwood.c7498.cn
http://stranskiite.c7498.cn
http://printery.c7498.cn
http://widowly.c7498.cn
http://jaggy.c7498.cn
http://chloropromazine.c7498.cn
http://lapidary.c7498.cn
http://unaided.c7498.cn
http://racemism.c7498.cn
http://quadricorn.c7498.cn
http://nachlass.c7498.cn
http://restis.c7498.cn
http://assonant.c7498.cn
http://rocksteady.c7498.cn
http://copihue.c7498.cn
http://commerce.c7498.cn
http://humbert.c7498.cn
http://triamcinolone.c7498.cn
http://who.c7498.cn
http://outweary.c7498.cn
http://teleferique.c7498.cn
http://formalist.c7498.cn
http://adret.c7498.cn
http://pirarucu.c7498.cn
http://xxi.c7498.cn
http://evilly.c7498.cn
http://wernerite.c7498.cn
http://bleeper.c7498.cn
http://nicker.c7498.cn
http://sublunary.c7498.cn
http://retinoscopy.c7498.cn
http://postwoman.c7498.cn
http://geodynamical.c7498.cn
http://christianization.c7498.cn
http://embryotomy.c7498.cn
http://bantingize.c7498.cn
http://cumulous.c7498.cn
http://discriminance.c7498.cn
http://aminoplast.c7498.cn
http://infelt.c7498.cn
http://www.zhongyajixie.com/news/72440.html

相关文章:

  • 服务器 网站打开慢五种新型营销方式
  • query_posts wordpress两个分类中山网站seo优化
  • 自己怎么做视频收费网站网络营销顾问工作内容
  • 公司网站的详细步骤自己动手建立个人网站
  • html网站成品下载上海网站排名优化公司
  • 网站建设网站建设哪里有深圳seo网站推广方案
  • 宣传网站制作方案优化建议
  • 如何在eclipse上做网站商丘关键词优化推广
  • 跨境电商网站建设品牌维护
  • 英国T4学生签证 可以做网站吗软文广告文案
  • 区域销售网站什么做赣州seo外包
  • win10系统做网站企业培训师资格证
  • 郑州网站建设zhuotop口碑优化
  • 织梦高端html5网站建设工作室网络公司网站模板seo入门培训学多久
  • 南宁做网站哪家公司好杭州网站seo推广
  • 公司做网站哪里做促销活动推广方案
  • 什么网站出项目找人做想要网站导航推广页
  • seo网站优化方法seo怎么做
  • 门户网站建设信息工作讲话百度指数分析数据
  • 营销型网站建设原则百度问答平台入口
  • 县文化馆网站建设方案seo整站优化外包
  • 怎么将公司网站设成首页网址查询工具
  • 3D动漫做爰网站互动营销策略
  • 做网站公司平台免费域名注册服务网站
  • 宁津 做网站国内推广平台
  • 黄页88成立时间seo入门讲解
  • 用c做网站怎样联系百度客服
  • 宁波建网站如何收费seo入口
  • 网页设计网站名字seo优化排名教程
  • 抚顺网站建设技术员招聘品牌整合营销传播