Arrays and it's Method

Arrays and it's Method

Table of contents

It is a collection of items with the index number

Arrays are variables that can hold more than one value [], we can access the values present in the array by variable name(Index_no), and we have different properties to do work like variable_name.length... we can add value in the array by variable_name[index]='define' and we can even change the value already present in the array

Arrays are immutable they can be changed Strings are mutable it can't be changed. Arrays are of object type (typeof)

Some Array Methods are.

  1. toString() = convert an array to a string of comma-separated value convert it by .toString() method

     cnsole.log(number.toString())
    
  2. join () = it is used to attach some value with all the array values before every value presents variable_name('define')

  3. pop () = as the name suggests its use to pop the last value of the array and modifies this original array list var.pop()

  4. push () = it simply pushes the value to an array list at the last of the index and it also modifies the original array .push()

  5. concat () = it use to join the array with the given array

     let a1 = [1,2,3]
     let a2 = [4,5,6]
     let a3 = [7,8,9]
     a1.concat(a2,a3)   -> [1,2,3,4,5,65,7,8,9]
    
  6. shift () = it also works the same as pop but removes the first value of the array and also modifies the real list .shift()

  7. unshift () = by using this method we can just insert the value to the array the value will be inserted on the first palace in the array list fix.unShift()

  8. delete () = An array element is deleted by using the delete method, it also affects the original array when the value is deleted it is an operator.

  9. sort () = sort method use to sort array Alphabetically and the change also modifies the original array

     let set = [4,6,3,1,9]
     set.sort()  -> [1,3,4,6,9]
    

    sort takes an optional compare function, if this function provides the first argument basic principle of sorting

  10. splice () = It takes out a piece from an array and creates a new array by the new values present in it on biases of index.

    let num = [1,2,3,4,5]
    num.slice(2,4)  -> [3,4]
    
  11. reverse () = it is a simple method that uses to reverse the order of the array from last to first

  12. length () = it is used to count the total length of the array

  13. map () = It is one of the importhent array methods which is use to give command to all the values in an array like sqrt or add it will be applied to all.

let comnd = [2,4,6,8,]
console.log(comnd.map())  -> [4,16,32.64]

There is a Bonus method i.e table() - it is use to print array with value in a proper table form on to the terminal " console.table(name);