adds last, first, remove, contains, isEmpty and few more methods/properties to Array utilizing Object.defineProperty
npm install array-sugar
|2||downloads in the last day|
|13||downloads in the last week|
|24||downloads in the last month|
|Version||0.2.4 last updated 4 months ago|
|Keywords||array, array-methods, extend, sugar, syntactic sugar|
Array.range(1,3) instead [1, 2, 3]; array.contains(o) instead array.indexOf(o) != -1 array.remove(o) instead array.splice(array.indexOf(o), 1) //remove returns true when o was removed array.replace(o, n) instead array[array.indexOf(o)] = n; array.findOne(test) instead array.filter(test); array.clear() instead array.length = 0 array.copy() instead array.slice(0) array.insert(i,item) instead array.splice(i, 0, item); //plus it can take variable number of args array.isEmpty instead array.length == 0 array.first instead array array.last instead array[array.length-1]
Usable in any environment that supports Object.defineProperty(oldest would probably be IE9).
Available through npm and bower, just require(or include in index.html) and you should be good to go.
npm install array-sugar bower install array-sugar
Tests via nodeunit included.
Angular ngSanitize module in version 1.2.0-rc2 in it's method assigns to arr.last and this collides with our 'last' getter. So beware, I have created a pull request so that ngSanitize doesn't break, but who knows when it is going to be merged. For now, use ngSanitize from my fork: compatible ngSanitize
Missing any sugar? Please do submit a pull or feature request.