Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pop off the first array element with jquery?

I'm iterating through an array of json data but need to remove the first element prior to the iteration. How do I remove the initial element? This is what I have so far:

    $.post('player_data.php', {method: 'getplayers', params: $('#players_search_form').serialize()}, function(data) {

        if (data.success) {

           // How do I remove the first element ?

            $.each(data.urls, function() {
                ...
            });
        }

    }, "json");
like image 470
Paul Avatar asked Nov 07 '12 16:11

Paul


1 Answers

Plain javascript will do:

data.urls.shift()

On shift() method:

Removes the first element from an array and returns that element. This method changes the length of the array.

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/shift

like image 125
Adriano Carneiro Avatar answered Oct 03 '22 00:10

Adriano Carneiro