javascript

How to splice the first few items from an array in Javascript

If you need to retrieve the first X items from an array in Javascript you can use the built-in splice method.

example: remove all but the first 3 items from an array:

data = ['one', 'two', 'three', 'four', 'five']  
data = data.splice(0, 3);  

["one", "two", "three"]

more JavaScript posts