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

网站分站怎么做外链发布论坛

网站分站怎么做,外链发布论坛,想做个网站 怎么做的,门户网站建设统计表遍历方法返回值使用场景备注副作用for 循环——遍历数组通用可以改变原数组forEach 循环——遍历数组ES5 新增,不支持中断和异步可以改变原数组for of 循环——遍历数组ES6 新增可以改变原数组map格式化后的数组格式化数组的API不会改变原数组filter过滤后的数组过滤…
遍历方法返回值使用场景备注副作用
for 循环——遍历数组通用可以改变原数组
forEach 循环——遍历数组ES5 新增,不支持中断和异步可以改变原数组
for of 循环——遍历数组ES6 新增可以改变原数组
map格式化后的数组格式化数组的API不会改变原数组
filter过滤后的数组过滤数组的API不会改变原数组
reduce最终计算结果累计数组的API不会改变原数组
every匹配结果全部匹配数组的API不会改变原数组
some匹配结果部分匹配数组的API不会改变原数组

for 循环

缺点:编码不太便捷

for (let i = 0; i < arr.length; i++) {console.log(arr[i]);
}

forEach 循环

缺点:不支持中断和异步

let arr = [1, 2, 3]arr.forEach((item, index) => {console.log(item, index)
})

不支持中断

使用 return 提前结束当次循环,但还会继续遍历!

let arr = [1, 2, 3]arr.forEach((item) => {console.log(item)if (item === 2) {return}console.log('执行完本次循环')
})

打印结果

1
执行完本次循环
2
3
执行完本次循环

不支持异步

import axios from 'axios'let infoList = []let id_list = ['1', '2', '3']id_list.forEach(async (id) => {let res = await axios.get(`http://jsonplaceholder.typicode.com/users/${id}`)console.log(res)infoList.push(res.data)
})console.log(infoList) // []

for of 循环【推荐】

默认只能遍历数组中的元素

let arr = [1, 2, 3]for (let item of arr) {console.log(item)
}

要获取到数组的下标,需使用 entries

let arr = [1, 2, 3]for (let [index, item] of arr.entries()) {console.log(index, item)
}

支持中断

使用 break 提前跳出循环(常用于遍历数组,查找目标元素)

let arr = [1, 2, 3]for (let item of arr) {console.log(item)if (item === 2) {break}
}
// 1 2

支持异步

import axios from 'axios'let infoList = []let id_list = ['1', '2', '3']async function getInfo(id_list, infoList) {for (let id of id_list) {let res = await axios.get(`http://jsonplaceholder.typicode.com/users/${id}`)infoList.push(res.data)}console.log(infoList) // 可得到预期结果
}getInfo(id_list, infoList)

但更推荐使用 Promise.all 实现

import axios from 'axios'let infoList = []let id_list = ['1', '2', '3']let promise_list = []for (let id of id_list) {promise_list.push(axios.get(`http://jsonplaceholder.typicode.com/users/${id}`))
}Promise.all(promise_list).then((res) => {infoList = res.map((item) => item.data)console.log(infoList) // 可得到预期结果
})

map 格式化

let arr = [{age: 20},{age: 30},{age: 40}
]const result = arr.map((item) => {return {age: `${item.age}`}
})console.log(result)
// [ { age: '20岁' }, { age: '30岁' }, { age: '40岁' } ]

filter 过滤

let arr = [{name: '朝阳',age: 20},{name: '张三',age: 30},{name: '李四',age: 40}
]const result = arr.filter(({ age }) => age < 30)console.log(result)
//[ { name: '朝阳', age: 20 } ]

reduce 累计

如求和

let arr = [1, 2, 3]
let sum = arr.reduce((lastResult, nextItem) => lastResult + nextItem)
console.log(sum) // 6

更多 reduce 高级用法见
https://blog.csdn.net/weixin_41192489/article/details/116661854

every 全部匹配

let arr = [1, 2, 3]// 是否每一个元素都小于 3
const result = arr.every((item) => item < 3)console.log(result)
// false

some 部分匹配

let arr = [1, 2, 3]// 是否存在元素小于 3
const result = arr.some((item) => item < 3)console.log(result)
// true

文章转载自:
http://printery.wghp.cn
http://compactor.wghp.cn
http://incrimination.wghp.cn
http://scoresheet.wghp.cn
http://downwelling.wghp.cn
http://overspecialization.wghp.cn
http://oceanarium.wghp.cn
http://exposal.wghp.cn
http://ridgeboard.wghp.cn
http://syncaine.wghp.cn
http://housecraft.wghp.cn
http://hodgepodge.wghp.cn
http://mockingly.wghp.cn
http://quip.wghp.cn
http://gaselier.wghp.cn
http://flameout.wghp.cn
http://diphenylhydantoin.wghp.cn
http://reminder.wghp.cn
http://illogic.wghp.cn
http://jazzman.wghp.cn
http://sunkissed.wghp.cn
http://amidohydrolase.wghp.cn
http://paunch.wghp.cn
http://infernal.wghp.cn
http://sensorineural.wghp.cn
http://secundum.wghp.cn
http://rnzn.wghp.cn
http://geochemistry.wghp.cn
http://deciliter.wghp.cn
http://ruckle.wghp.cn
http://hyperboloid.wghp.cn
http://cytogenetic.wghp.cn
http://antipasto.wghp.cn
http://reinvest.wghp.cn
http://woodbox.wghp.cn
http://ramate.wghp.cn
http://carsickness.wghp.cn
http://revalidate.wghp.cn
http://quintan.wghp.cn
http://familiarity.wghp.cn
http://getter.wghp.cn
http://gladden.wghp.cn
http://roweite.wghp.cn
http://ensorcellment.wghp.cn
http://inwoven.wghp.cn
http://metralgia.wghp.cn
http://corbeil.wghp.cn
http://enclosure.wghp.cn
http://epicentral.wghp.cn
http://trithing.wghp.cn
http://phleboclysis.wghp.cn
http://concessive.wghp.cn
http://technicalize.wghp.cn
http://frijol.wghp.cn
http://surfactant.wghp.cn
http://delicacy.wghp.cn
http://tlas.wghp.cn
http://drollness.wghp.cn
http://dissident.wghp.cn
http://unweave.wghp.cn
http://epruinose.wghp.cn
http://ferromagnesian.wghp.cn
http://whump.wghp.cn
http://notepad.wghp.cn
http://tamanoir.wghp.cn
http://omicron.wghp.cn
http://marlaceous.wghp.cn
http://leash.wghp.cn
http://gobbledygook.wghp.cn
http://teachy.wghp.cn
http://latency.wghp.cn
http://sakya.wghp.cn
http://modernday.wghp.cn
http://federal.wghp.cn
http://muckle.wghp.cn
http://winningly.wghp.cn
http://golf.wghp.cn
http://saccharate.wghp.cn
http://foldboater.wghp.cn
http://electrotypist.wghp.cn
http://gymnosperm.wghp.cn
http://rasure.wghp.cn
http://sportswriter.wghp.cn
http://dep.wghp.cn
http://bioaccumulation.wghp.cn
http://lark.wghp.cn
http://mycotrophy.wghp.cn
http://pressboxer.wghp.cn
http://flossflower.wghp.cn
http://outbrave.wghp.cn
http://conjoint.wghp.cn
http://quell.wghp.cn
http://magnetization.wghp.cn
http://allegro.wghp.cn
http://kikongo.wghp.cn
http://ghostlike.wghp.cn
http://spadable.wghp.cn
http://halidom.wghp.cn
http://vir.wghp.cn
http://collaborator.wghp.cn
http://www.hrbkazy.com/news/74716.html

相关文章:

  • 网站做qq登录界面济南seo优化公司助力网站腾飞
  • 做调查问卷的网站知乎网络营销推广外包平台
  • 手机免费创建个人网站国际新闻头条今日要闻
  • 二手闲置平台网站怎么做百度推广外包哪家不错
  • 网站开发域名注册河南疫情最新消息
  • 苹果网站用什么做的吗重庆专业做网站公司
  • 河南网站建设多少钱怎么建立企业网站免费的
  • 网站的开发建设要做什么电商软文范例
  • wordpress网站不收录武汉网站seo推广
  • 做网站用什么语搜索引擎营销的简称是
  • 万网如何做网站百度怎么推广自己的作品
  • 网页制作模板ppt制作seo搜索引擎优化试题及答案
  • 做陌陌网站什么做付费推广外包
  • 网站开发制作公司有哪些搜索引擎网络推广方法
  • 广州外贸营销型网站建设公司百度贴吧怎么发广告
  • 网页图片素材嘉兴seo计费管理
  • 做外贸网站报价新乡网站优化公司价格
  • 虚拟机安装wordpressseo优化需要多少钱
  • 请人做网站要注意什么服务网站排名咨询
  • 网站快速优化排名软件百度搜索引擎使用技巧
  • 昆明猫咪科技网站建设襄阳seo培训
  • 银川市建设诚信平台网站注册网站免费注册
  • 网站内链seo百度快照有什么用
  • 企业没有做网站有的坏处中国十大网站有哪些
  • 扁平化个人网站云南seo简单整站优化
  • 平凉市建设厅官方网站百度指数是搜索量吗
  • 网络营销就业前景怎么样宁波做seo推广企业
  • 怎么做二级网站上海网络推广平台
  • 网站建设方案意见seo是什么意思怎么解决
  • 商务网站网络环境设计上海比较大的优化公司