JavaScript Array: Remove Element from Array

JavaScript Array: Remove Element from Array

In this tutorial, you will learn, how to remove the last element from array in javascript, remove the first element from array javascript, remove specific elements from array javascript with different techniques and examples.

This tutorial demonstrates various techniques and methods with examples to removing the first, last, or specific index elements from a javascript array.

Remove Element From Array javaScript

This tutorial demonstrates an easy way to remove the first, last specific index element from an array using the js array methods like, pop(), shift(), and splice():

1. First Method – Array Shift() JavaScript

Use the javascript array shift() method, which is used to remove the first element of the array javascript.

Let’s take an example to remove the first element from an array javascript using array shift method:

var arr = [ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" ]; 

 arr.shift();

 console.log( arr );
 

Result of the above example:

After removed the first element from an array using javascript shift method. The output will look like:

["two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]

2. Second Method:- Array pop() javascript

Using the javaScript pop method, which is used to remove the last element of the array javascript, returns that new element array.

 var arr = [ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" ]; 

 arr.pop();

 console.log( arr );


Result of the above example

After removed the last element from an array using javascript pop method. The output will look like:

["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]

3. Third Method:- Array splice() javascript

Use the javascript splice() method, that is used to add or remove elements from an array in javascript.

Let’s take an example to remove specific index elements from array javascript. In this example, we will remove 1 to 2 index values from the array.

 var arr = [ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" ]; 

 arr.splice(1,2);

 console.log( arr );

Result of the above example

  ["one", "four", "five", "six", "seven", "eight", "nine", "ten"]
 

If you want to know more about javascript array methods, you may like

You may like

  1. Convert String to Array JavaScript
  2. JavaScript Array splice() Method By Example
  3. Sorting Using JavaScript Array Sort() Method
  4. JavaScript: Clone an Array & Object By Examples
  5. javaScript Push() Array By Example
  6. javaScript Push Array, Items Into Array Example
  7. Convert Array to Comma-Separated String javaScript
  8. JavaScript Check the Object | isArray() Function
  9. JavaScript: Important Array Methods

AuthorTuts Make

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *