DEV Community

Cover image for How to Remove First Element from Array in Javascript
Code And Deploy
Code And Deploy

Posted on

4 2

How to Remove First Element from Array in Javascript

Originally posted @ https://codeanddeploy.com visit and download the sample code: https://codeanddeploy.com/blog/javascript/how-to-remove-first-element-from-array-in-javascript

In this post, I'm sharing a short post on how to remove the first element value from an array in Javascript. If you need to remove the first value of the array before processing the data then array.shift() done this.

Here is the example solution below:

<script>
var websites = ['google.com', 'facebook.com', 'youtube.com'];

websites.shift();

console.log(websites);

// result: ["facebook.com", "youtube.com"]
</script>
Enter fullscreen mode Exit fullscreen mode

I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/javascript/how-to-remove-first-element-from-array-in-javascript if you want to download this code.

Happy coding :)

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ β€’ β€’ Edited

Or, without mutation:

let websites = ['google.com', 'facebook.com', 'youtube.com'];
[, ...websites] = websites
Enter fullscreen mode Exit fullscreen mode
πŸ‘‹ Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s dayβ€”drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay