JavaScript Array Remove Element

JavaScript Array Remove Element

Hello friends, Today we will how to remove array element from array in JavaScript.  In this example we will show remove elements from array in any position. You will learn JavaScript array remove element at index.

Here, You will show remove elements from the end of an array, remove elements from the start of an array, remove elements from the specific index of an array, remove elements in programmatically.

Remove Array elements by using pop() method

<script>
function func() {
    var arr = ["shift", "splice", "filter", "pop"];
 
    // Popping the last element from the array
    var popped = arr.pop();
    document.write("Removed element: " + popped + "<br>");
    document.write("Remaining elements: " + arr);
}
func();
</script>

Output

Removed element: pop
Remaining elements: shift, splice, filter

Remove Array elements by using shift() method

<script>
function func() {
    var arr = ["shift", "splice", "filter", "pop"];
 
    // Removing the first element from array
    var shifted = arr.shift();
    document.write("Removed element: " + shifted + "<br>");
    document.write("Remaining elements: " + arr);
}
func();
</script>

Output

Removed element: shift
Remaining elements: splice, filter, pop

Remove Array elements by using splice() method

<script>
 
function func() {
    var arr = ["shift", "splice", "filter", "pop"];
 
    // Removing the specified element from the array
    var spliced = arr.splice(1, 1);
    document.write("Removed element: " + spliced + "<br>");
    document.write("Remaining elements: " + arr);
}
func();
</script>

Output

Removed element: splice
Remaining elements: shift, filter, pop

Remove Array elements by Delete Operator

<script>
 
var array = ["lowdash", "remove", "delete", "reset"]
 
// Delete element at index 2
var deleted = delete array[2];
 
document.write("Removed: " + deleted + "<br>");
document.write("Remaining elements: " + array);
</script>

Output

Removed: true
Remaining elements: lowdash, remove,,reset

I hope you understand of JavaScript remove array element and it can help you…

Read Also :  jQuery inArray() Function Example