Menu

Array Methods You Must Know
πŸ–ΌοΈ

Array Methods You Must Know

DEV CommunityΒ·Abhishek sahniΒ·6 months ago
#0Jl4huKv
#webdev#programming#javascript#beginners#array
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.