Download

Production(minified):

handyArrayTools.js


Docs

Remove Duplicates


var arrayWithDuplicates = ["moose","deer","deer","antelope","moose"]
var arrayWithoutDuplicates = removeDuplicates(arrayWithDuplicates)
                    

arrayWithoutDuplicates will equal ["deer","antelope","moose"].

Note - the array that you pass to the function only supports integers and strings, you can also only pass all integers or all strings.


Delete Occurences


var arrayWithHi = ["hi","deer","hi","antelope","hi"]
var arrayWithoutHi = removeDuplicates(arrayWithHi,"hi")
                    

arrayWithoutHi will equal ["deer","antelope"].

Note - the array that you pass to the function only supports integers and strings, you can also only pass all integers or all strings.


Array To Object


var arr = ["hello", "good morning", "good evening", 43 , {"hi":"people"},true ]
var obj = arrayToObject(arr,1)
                    
                    

obj will equal {"1":"hello", "2":"good morning","3":"good evening", "4": 43 , "5":{"hi":"people"}, "6": true }.

The first parameter of arrayToObject() is the array to convert and the second is the number to start counting the objects keys from.

Of course, the key can only be a string, but the value can be anything- a string, integer, float, bolean, array, or even another object.

Stringify All Elements


var arr = ["hello", 43 , {"hi":"people"},true ]
strArr = stringifyAll(arr)
                    
                    

All elements in strArr will be strings.


Bug Report