[Day 22]从零开始学习 JS 的连续-30 Days---阵列操作介绍 (下篇)

阵列操作介绍 (下篇)

介绍四种阵列运用:

  1. map
  2. filter
  3. find
  4. findlndex

3. find

  1. 寻找阵列里面第一笔符合条件的资料。
const num = [ 1 , 2 , 3 , 7 , 8 , 9 ]
const newNum = num.find(function(item){
  return item >= 5;
})
console.log(newNum);


如图所示找出大於5的值,理论会印出7、8、9这三个值,但
使用 find 只会找寻出符合条件的第一笔资料。

4. findIndex

  1. 找寻出符合条件的资料索引。(资料在阵列的排序)
const colors = [ "red" , "black" , "white" , "blue" ]
const color = colors.findIndex(function(item){
  return item == "black";
})
console.log(color);


如图所示使用 findIndex 找出符合条件的资料索引。
回传的值为 1 ,阵列 0 为排序第一个, 1 为排序第二个。

阵列操作整理

  1. map 、 filter 、 find 、 findIndex 四种都不会影响原先阵列。
  2. map 在运算後重新整理出新阵列。
  3. filter 筛选出符合条件的资料再重新组成新阵列。
  4. find 找出第一笔符合的资料。
  5. findndex 找出符合资料的排序。

今天到此结束。


<<:  [Day28] 动画篇5

>>:  Day22-Kubernetes 那些事 - Namespace

Day 27:语系包在 i 身上-Vue I18n 前置作业

因应国际化的需求,专案决定也要符合 international 的规格,Navbar 右上角的「选择...

Day28: 今天来聊一下将syslog 资料连线到 Azure Sentinel

规划syslog连接器 我们可以使用适合的Linux Log Analytics Agent,从以L...

Day-29 Massive Storage Management

Massive Storage Management tags: IT铁人 其实这块要讲的就是有关D...

[Day30]Flutter Netflix UI 使用shared_preferences

大家好,今天是最後一天,今天跟大家介绍shared_preferences,可以把一些简单的设定的东...

★ 2021 IPBC Taiwan|创新科技论坛-智胜5G 领航未来! ★ 经济部工业局 主办 !

★2021 IPBC Taiwan|创新科技论坛-智胜5G 领航未来!★ 经济部工业局 主办! ht...