Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  122] [ 4]  / answers: 1 / hits: 17183  / 12 Years ago, wed, november 7, 2012, 12:00:00

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);

More From » jquery

 Answers
26

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


[#82125] Tuesday, November 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braydon

Total Points: 0
Total Questions: 102
Total Answers: 111

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
;