adds last, first, remove, contains, isEmpty and few more methods/properties to Array utilizing Object.defineProperty
Arrayrange13 instead 1 2 3;Arraymin1 3 instead Mathminapplynull1 3;Arraymax1 3 instead Mathmaxapplynull1 3;arraycontainso instead arrayindexOfo != -1arrayremoveo instead arraysplicearrayindexOfo 1 //remove returns true when o was removedarrayreplaceo n instead arrayarrayindexOfo = n;arrayfindOnetest instead arrayfiltertest0;arrayclear instead arraylength = 0arraycopy instead arrayslice0arrayunique instead arrayfilterreturn i === aindexOfitm;arrayuniquepushitem instead if ~selfindexOfitem selfpushitem;arrayuniquemergearr instead as previous but for all items in arrarrayinsertiitem instead arraysplicei 0 item; //plus insert can take variable number of args, not just onearrayisEmpty instead arraylength == 0arrayfirst instead array0arraylast instead arrayarraylength-1
Usable in any environment that supports Object.defineProperty(oldest would probably be IE9).
Available through npm and bower, just require(or include with regular script tag) and you should be good to go.
npm install array-sugar bower install array-sugar jspm install npm:array-sugar
Then require('array-sugar'); and you're done.
Angular ngSanitize module in it's method assigns to arr.last and this collides with our 'last' getter.
If I am writing a web app, NOT a library/framework, I don't consider this a bad practice. I have quite few libraries and I do not use array-sugar in them even if It would be helpful most of the time. Users of these libraries would have their Array unexpectedly extended and that is not a good practice. If you are building an end product used by end-user, I think it is quite allright to have these methods straight on array.prototype.
Missing any sugar? Please do submit a pull or feature request.