JavaScript Array Functions Cheat Sheet Part 1

 JavaScript Array Functions Cheat Sheet Part 1




concat()

concat() merge two or more arrays

Syntax


  const new_array = old_array
    .concat([value1[, value2[, ...[, valueN]]]])



Example


  [1020].concat([50], [7090])
  // [ 10, 20, 50, 70, 90 ]



 

copyWithin()

copyWithin() copies part of array to another location

Syntax


  arr.copyWithin(target[, start[, end]])



Example


  [ 1020304050 ].copyWithin(0,2
   // [ 30, 40, 50, 40, 50 ]



entries()

Array Iterator with key/value pairs for each index


Syntax


  arr.entries()



Example


  ['a''b''c']
  .entries() // Array Iterator {  }
    .next() // { value: (2) […], done: false }
    .value // Array [ 0, "a" ]





every()

every() tests if all elements in the array pass the test

Syntax


  arr.every(callback(element[, index[, array]])[, thisArg])




Example


  [13040].every(val => val > 0// true




fill()

fill() changes elements in an array to a static value

Syntax


  arr.fill(value[, start[, end]])



Example


  [1234].fill('x'13
  // [ 1, "x", "x", 4 ]



filter()


filter() creates a new array with elements that pass the test

Syntax



  let newArray = arr
    .filter(callback(
      element[, index, [array]]
    )[, thisArg])

   


Example


    [11056].filter(val => val > 5
    // [ 10, 6 ]




Thanks for reading... 👏👏👏


Recommend Post

Reactions

Post a Comment

0 Comments