Blogger Information
Blog 77
fans 0
comment 2
visits 55709
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组的一些基本函数
南瓜又个梦
Original
634 people have browsed it

求数组里的奇数和

  1. let scores = [95,91,59,55,42,82,72,85,67,66,55,91]
  2. let sum = scores.reduce((sum, item)=>{
  3. return item%2===0?sum+0:sum+item
  4. },0)
  5. console.log(sum) // 奇数之和:598

把数字变成星期

  1. let arr = [0,1,2,2,3,3,3,4,4,4,4,6]
  2. let arr2 = arr.map((i)=>{
  3. const hash = {0:'周日',1:'周一',2:'周二',3:'周三',4:'周四',5:'周五',6:'周六'}
  4. return hash[i]
  5. })

找出所有大于 60 分的成绩

  1. let scores = [95,91,59,55,42,82,72,85,67,66,55,91]
  2. let scores2 = scores.filter(n => n>= 60)
  3. console.log(scores2) // [95,91,82,72,85,67,66, 91]
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post