Deleting Items from an Array



Hello everyone In this Post I am going to explain the basic about Deleting Items in JavaScript Array.

In JavaScript Items can be deleted by using 2 JavaScript function which are pop() & shift().

Deleting a Item at the end of Array

pop() function are used to delete the last element of the array.

Let’s suppose we have a array as

var a = [A, B, C];

var b = a.pop();

now the result array will be a =  [A, B]. pop() function delete the last element from the array and  we can save the value of the deleted element like i did in above example. I have stored the deleted element  in variable b so now b contains the last element which is C.

Deleting Item at the beginning of Array

shift() function are used to delete the first element of the array.

Let’s suppose we have a array as

var a = [A, B, C];

var b = a.shift();

now the result array will be a =  [B, C]. shift() function delete the first element from the array and  in this case also we can save the value of the deleted element like i did in above example. I have stored the deleted element  in variable b so now b contains the last element which is A.

 

Stay tuned for the PHP Magento, WordPress, JavaScript and Magento2 latest tutorial and updates, Hope you enjoyed reading, if you need the professional Magento Development / PHP we can help you, just Click on the Link and send me your requirements.

Please Like the Post on Facebook or Google+.