December 21, 2022
Estimated Post Reading Time ~

JOURNEY WITH JAVASCRIPT Basic Methods

JOURNEY WITH JAVASCRIPT   
  • Arrays in JavaScript  
  • 10 frequently used array methods


Arrays: An array is an ordered collection of data that can store multiple values of the same data type. We can access elements of an array using indices (0, 1, 2 …).



There are several built-in methods for arrays that allow you to manipulate the data stored in them.

1. at( )
The at( ) method returns the value of the element at the specified index in an array.



2. push( )
The `push( )` method adds one or more elements to the end of an array and returns the new length of the array. 

3. pop( ) 
The `pop( )` method removes the last element from an array and returns that element. This method changes the length of the array.



4. shift( ) 
The `shift( )` method removes the first element from an array and returns that removed element. 

5. unshift( ) 
The `unshift( )` method adds one or more elements to the beginning of an array and returns the new length of the array.



6. concat( )
It is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array. 7. join( ) It creates and returns a new string by concatenating all of the elements in an array, separated by commas or a specified string.



8. reverse( ) 
It reverses an array in place and returns the reference to the same array, the first array element now becoming the last, and the last array element becoming the first.



9. sort( ) 
It sorts the elements of an array in place and returns the reference to the same array, now sorted. The default sort order is ascending, It first converts the elements into strings, then compares their sequences of UTF-16 code unit values.  
Read resources docs 




10. slice( ) 
It returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.




By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.