In python, I can remove the first item from array xs like so:
xs = xs[1:]
How could I do that with the following javascript array?
var data = {{data}}
In python, I can remove the first item from array xs like so:
xs = xs[1:]
How could I do that with the following javascript array?
var data = {{data}}
The JavaScript splice function, not an specific of jQuery.
var fruit = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
var removed = fruit.splice(0, 1);
console.log(removed);
console.log(fruit);
The result is ["Orange", "Apple", "Mango", "Kiwi"]
shift returns the value directly, splice will return an array of the values removed. So both do the job, the one you pick depends on what you want to do with the result.splice would be preferred if we were removing more than 1 from the start. It's also similar to the Python version. In this case shift is simpler though.If you want to get the first value out of an array and remove it from the array, you can use Array#shift (MDN | spec):
var a = [1, 2, 3, 4]; // An array
var first = a.shift(); // Remove and return the first entry
console.log(first); // Show the value we got
console.log(a); // Show the updated state of the array