Menu

Post image 1
Post image 2
1 / 2
0

Array Methods You Must Know

DEV Community·Abhishek sahni·about 1 month ago
#0Jl4huKv
Reading 0:00
15s threshold

In this blog we are going to learn most useful methods of arrays in javaScript. Javascript provides multiple built-in methods for common tasks so, that se don't need to write the logic from scratch. push() and pop() : Both function perform very simple and common task. push() : From the name you can guess it is used to push(add) new values in array at the end of the array and return new array length. const fruits = [ ' apple ' , ' banana ' ]; const newLength = fruits . push ( ' orange ' , ' mango ' ); console . log ( fruits ); // ["apple", "banana", "orange", "mango"] console . log ( newLength ); // 4 Enter fullscreen mode Exit fullscreen mode pop() : This method remove the last element from the array from original array. it returns the removed element. const fruits = [ ' apple ' , ' banana ' , ' cherry ' ]; const lastFruit = fruits . pop (); console . log ( fruits ); // ["apple", "banana"] (original array modified) console .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More