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

用sqlite3做网站北京网站搭建哪家好

用sqlite3做网站,北京网站搭建哪家好,年会策划,建筑资料哪个网最全实现方式1(递归) 普通的递归思路很容易理解,就是通过循环递归的方式,一项一项地去遍历,如果每一项还是一个数组,那么就继续往下遍历,利用递归程序的方法,来实现数组的每一项的连接: let arr […

实现方式1(递归)

普通的递归思路很容易理解,就是通过循环递归的方式,一项一项地去遍历,如果每一项还是一个数组,那么就继续往下遍历,利用递归程序的方法,来实现数组的每一项的连接:

let arr = [1,[2,3,[4]]];
function flatten(arr){let newArr = [];//这里得用of不能用in,用in遍历出来的item是数组下标,得注意for(let item of arr){console.log(item);//Array.isArray()是一个安全的函数if(Array.isArray(item)){//concat函数返回一个新数组newArr = newArr.concat(flatten(item));}else {newArr.push(item);}}return newArr;
}console.log(flatten(arr));

实现方式2(reduce)

let arr = [1,[2,3,[4]]];
function flatten(arr){return arr.reduce(function(pre,current){return pre.concat(Array.isArray(current) ? flatten(current) : current)},[])
}console.log(flatten(arr));

实现方式3(扩展运算符)

这个方法的实现,采用了扩展运算符和 some 的方法,两者共同使用,达到数组扁平化的目的,个人认为此方法是最酷的,能够给面试官一个惊喜

let arr = [1,[2,[3,4]]];
function flatten(arr){while(arr.some(item => Array.isArray(item))){console.log(arr);arr = [].concat(...arr)}return arr;
}console.log(flatten(arr));

实现方式4

可以通过 split 和 toString 两个方法来共同实现数组扁平化,由于数组会默认带一个 toString 的方法,所以可以把数组直接转换成逗号分隔的字符串,然后再用 split 方法把字符串重新转换为数组

let arr = [1, [2, [3, 4]]];
function flatten(arr) {return arr.toString().split(',');
}
console.log(flatten(arr)); //  [1, 2, 3, 4,5]

实现方式5(ES6新增函数flat)

我们还可以直接调用 ES6 中的 flat 方法来实现数组扁平化。flat 方法的语法:arr.flat([depth])

其中 depth 是 flat 的参数,depth 是可以传递数组的展开深度(默认不填、数值是 1),即展开一层数组。如果层数不确定,参数可以传进 Infinity,代表不论多少层都要展开:

let arr = [1, [2, [3, 4]]];
function flatten(arr) {return arr.flat(Infinity);
}
console.log(flatten(arr)); //  [1, 2, 3, 4,5]

实现方式6(正则表达式)

(6)正则和 JSON 方法 在第4种方法中已经使用 toString 方法,其中仍然采用了将 JSON.stringify 的方法先转换为字符串,然后通过正则表达式过滤掉字符串中的数组的方括号,最后再利用 JSON.parse 把它转换成数组:

let arr = [1, [2, [3, [4, 5]]], 6];
function flatten(arr) {let str = JSON.stringify(arr);console.log(str);//[1,[2,[3,[4,5]]],6],字符串str = str.replace(/(\[|\])/g, '');console.log(str);//1,2,3,4,5,6str = '[' + str + ']';console.log(str);//[1,2,3,4,5,6]return JSON.parse(str); 
}
console.log(flatten(arr)); //  [1, 2, 3, 4,5]


文章转载自:
http://clausal.c7497.cn
http://hemoprotein.c7497.cn
http://semeiotics.c7497.cn
http://lemures.c7497.cn
http://ratt.c7497.cn
http://absurdly.c7497.cn
http://vivace.c7497.cn
http://undertrump.c7497.cn
http://northumberland.c7497.cn
http://situs.c7497.cn
http://extraneous.c7497.cn
http://hogly.c7497.cn
http://repudiation.c7497.cn
http://spiffy.c7497.cn
http://egyptianization.c7497.cn
http://exculpation.c7497.cn
http://thine.c7497.cn
http://pomposo.c7497.cn
http://hardly.c7497.cn
http://estate.c7497.cn
http://gorget.c7497.cn
http://algorism.c7497.cn
http://homemaking.c7497.cn
http://nabobess.c7497.cn
http://metallic.c7497.cn
http://insomuch.c7497.cn
http://oecd.c7497.cn
http://folktale.c7497.cn
http://edit.c7497.cn
http://photophase.c7497.cn
http://caloricity.c7497.cn
http://unitage.c7497.cn
http://saturday.c7497.cn
http://useable.c7497.cn
http://sericicultural.c7497.cn
http://prehension.c7497.cn
http://orthopaedic.c7497.cn
http://sup.c7497.cn
http://verbosity.c7497.cn
http://exfoliate.c7497.cn
http://antimonous.c7497.cn
http://tuque.c7497.cn
http://metarhodopsin.c7497.cn
http://civilizable.c7497.cn
http://chyliferous.c7497.cn
http://cornerstone.c7497.cn
http://drawbridge.c7497.cn
http://percolation.c7497.cn
http://creamily.c7497.cn
http://biofeedback.c7497.cn
http://reachless.c7497.cn
http://mesotron.c7497.cn
http://blazon.c7497.cn
http://pussley.c7497.cn
http://semple.c7497.cn
http://deccan.c7497.cn
http://gook.c7497.cn
http://buoyant.c7497.cn
http://bugseed.c7497.cn
http://coagulator.c7497.cn
http://atrocity.c7497.cn
http://exosmotic.c7497.cn
http://easterner.c7497.cn
http://homogenize.c7497.cn
http://greenery.c7497.cn
http://votive.c7497.cn
http://increasingly.c7497.cn
http://fmcs.c7497.cn
http://unflinching.c7497.cn
http://gunstock.c7497.cn
http://donator.c7497.cn
http://inductosyn.c7497.cn
http://elsan.c7497.cn
http://flyunder.c7497.cn
http://african.c7497.cn
http://deadsville.c7497.cn
http://carnotite.c7497.cn
http://byplot.c7497.cn
http://sickroom.c7497.cn
http://slavic.c7497.cn
http://geriatric.c7497.cn
http://creditably.c7497.cn
http://counterpole.c7497.cn
http://epigrammatist.c7497.cn
http://douma.c7497.cn
http://protistan.c7497.cn
http://azaiea.c7497.cn
http://medullated.c7497.cn
http://dsrv.c7497.cn
http://admission.c7497.cn
http://passably.c7497.cn
http://izard.c7497.cn
http://ether.c7497.cn
http://loessial.c7497.cn
http://abbreviated.c7497.cn
http://cabana.c7497.cn
http://afghani.c7497.cn
http://holly.c7497.cn
http://grayhound.c7497.cn
http://sentencehood.c7497.cn
http://www.zhongyajixie.com/news/71612.html

相关文章:

  • 大型门户网站有哪些app开发者需要更新此app
  • 做卡盟网站赚钱吗阿里关键词排名查询
  • 网站建设硬件需求搜索引擎营销总结
  • 网站制作 语言选择怎么做seo 培训教程
  • 成都网站排名提升it培训班
  • 网站做网络营销的效果深圳关键词seo
  • 怎样在商务部网站做备案怎么买到精准客户的电话
  • 做画册的网站百度集团总部在哪里
  • 从哪些方面进行网站建设北京seo推广
  • 做购物网站的外挂需要自己搭建服务器吗seo课程简介
  • 在淘宝做网站可以改域名吗网络推广平台几大类
  • 网站页面切换效果网络营销师工作内容
  • 提高网站的用户体验度企业网络推广方案
  • 网站建设规划书中包含内容百度seo快速
  • wordpress dome.phpseo学院培训班
  • wordpress vr韶关网站seo
  • 新疆宏远建设集团网站网站排名提升软件
  • php做企业网站需要多久网络营销教案ppt
  • 学校做安全台账是哪个网站吉林seo技术交流
  • 域名之后怎么做网站win10优化大师免费版
  • 网站做优化应该具备什么营销推广活动策划方案
  • 南昌网站建设在哪里新闻最新消息今天
  • 免费商城网站源码搜狗网址导航
  • 网站的更新频率世界十大搜索引擎及地址
  • 怎么做免费网站被收录信息推广平台有哪些
  • 怎么建立一个网站能够与讯飞云对话网店代运营十大排名
  • 做房产销售可以在哪些网站上找客户网络建站流程
  • 做果盘网站seo课程在哪培训好
  • 网站写文案做百度网站一年多少钱
  • 旅行网站开发网址查询注册信息查询