# Arrays

There's nothing to say, just Array Methods 😃

# The Basic

concat() every() filter() forEach() indexOf() join() lastIndexOf() map() pop() push() reduce() reduceRight() reverse() shift() slice() some() toSource() sort() splice() toString() unshift()

# forEach

  • note: Array.forEach doesn't wait for async calls !!
  • pls use for...in or for

# find

arr.find

  • get the first element back that causes the given callback function to return true

# findIndex

arr.findIndex

  • findIndex returns the index of that element

# entries

arr.entries

  • Entries will return an array of arrays, where each child array is an array of [index, value]
var numbers = [1, 2, 3]; 
var val = numbers.entries(); 
console.log(val.next().value);   // [0,1] 
console.log(val.next().value);   // [1.2] 
console.log([...val]);           //[[0,1],[1,2],[2,3]]

# from

arr.from

  • convert two kinds of values to Arrays :
    • Array-like values
    • Iterable values like Set and Map
for (let i of Array.from('hello')) { 
   console.log(i) 
}
res: 
h                               
e                               
l                               
l                               
o

# keys

arr.keys()

  • returns the array indexes
Last Updated: 2022/3/4 下午3:36:18