Mivaweb Mivaweb - 3 months ago 5
AngularJS Question

Remove elements from array above an index AngularJS

Is there a quick helper for removing elements from an array above a certain index in AngularJS?

For instance:

You have an array with 5 elements:

[0][1][2][3][4]


I want to remove all elements above index 2:

Result

[0][1][2]

Answer

Yes, there is:

array.slice(start, end)

In your case, something like this:

array.slice(0, -2)