The push() method adds a new element to the end of the array.
and also you can get new array length by implementing like this,
The pop() method is used to remove the last element of the array.
If you want to get the pop value you need to implement like this,
By using this shift() method, you can remove the array first element. Refer the below example.
If you want to get the removed value, use
If you want to add a new element to the beginning, this is the method for that.
The concat() method creates a new array by merging existing arrays. If you want to merge two arrays, you can use this.
Here is another example,
Here is another example,
The slice() method slices out elements. If you use slice(1), array will remove first element. If you use slice(3), array will remove first 3 elements.
This is splice, not slice. Do not mess with this. Lol. The splice() method can be used to add new items to an array:
In here, “2” means the position where new elements should be added and the “0” means, how many elements should be removed. If you replace 0 with any number, let assume you will replace 0 with 1, you will get,
It means last element will remove from the array. If you add 3, the output will be [ ‘A’, ‘B’, ‘C’, ‘D’ ].
Because there is no 3 elements after you added position 2 (It means after “B” only has “E”. if your array has [“A”, “B”, “E”, “F”, “G”], then you will see after position 2, elements will remove).
If you want to get the index of an element, you can use this method.
If you want to find out an element is in your array or not, you can use this method.
Also you can use this method like this,
Find the index that you need to find something.
I am using map() method to multiply by 2 array elements.
Here is some documentation for more details – Click here
Here is another perfect example for this method – Click here
I am checking my every array element greater than 6 or not.
I am checking my array has element that greater than 6.
If you want to reverse your array element you can use this method.
Thank you for reading. If you are interesting on my article, make sure to follow my other articles as well.
- Android Studio Articles – https://builditmasters.com/category/android-studio/
- Android Studio Firebase Tutorial – https://builditmasters.com/category/android-studio-firebase-tutorial/
- C Programming – https://builditmasters.com/category/programming/
- Flutter – https://builditmasters.com/category/flutter/
- GitHub Tutorials – https://builditmasters.com/category/github/
- Java Programming – https://builditmasters.com/category/java-programming/
- MERN / MEVN Stacks – https://builditmasters.com/category/mern_mevn_stacks/
- Tech News – https://builditmasters.com/category/tech-news/
- Theory Lessons – https://builditmasters.com/category/theory-lessons/
- Adobe Tutorials – https://builditmasters.com/category/adobe-tutorials/