Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Pop a value from array, but not at the end of array

I have for example this array (each number is singolar, no one duplicate) called pvalue : 1 2 3 15 20 12 14 18 7 8 (sizeof 10).

I need for example to pop the value "15", and after this pvalue should be 1 2 3 20 12 14 18 7 8 (sizeof 9). How can do it?

the pop() function take the value at the end of the array. I don't want this :) cheers

EDIT

for(i=0; i<pvalue.length; i++) {
    if(pvalue[i]==param) {
        ind=i;
        break;
    }
}
pvalue.splice(ind, 1);
like image 230
markzzz Avatar asked Sep 19 '10 12:09

markzzz


1 Answers

To pop the first one off, use:

first = array.shift();

To pop any other one off, use:

removed = array.splice(INDEX, 1)[0];
like image 55
Delan Azabani Avatar answered Sep 24 '22 18:09

Delan Azabani