Welcome To Snipplr
Everyone's Recent JavaScript Snippets Tagged array
- All /
 - JavaScript /
 - HTML /
 - PHP /
 - CSS /
 - Ruby /
 - Objective C
 
If you need to sort an array in javascript this is how it should be done. Casting  toLowerCase() is optional but but necessary if fx "Anne" was spelled "anne"
        
        
        
            0 
        
        
            1211 
        
                    posted 15 years ago by fengelz
            I frequently pass an array of elements from an HTML form to PHP, normally a list of checkboxes for removing database records.  This will loop through an array of  checkbox's with the same name & build a delimited string from the checked values.  Afte...
        
        
        
            0 
        
        
            1154 
        
                    posted 15 years ago by verostudios
            I needed to break down a long string today and insert line breaks so I wrote this little function. You can use it to split a long string into chunks of a defined length and get them as an array or join them by a defined character (e.g. <br />)....
        
        
        
            0 
        
        
            1483 
        
                    posted 15 years ago by chlab
            This can be tested using the following piece of code
		var a = [1, 2, 3, 4, 5];
		alert(a.size());
        
        
        
            0 
        
        
            1093 
        
                    posted 15 years ago by arunpjohny
            This function is add 'each' function to the javascript Array object.
        
        
        
            1 
        
        
            964 
        
                    posted 15 years ago by arunpjohny
            Ensures all elements in an array are unique
newArray = myArray.unique();
        
        
        
            0 
        
        
            985 
        
                    posted 16 years ago by svenito
            This extends arrays withe a removeItems operation to remove all occurances of <item> from <array>
usage: myArray.removeItems("words");
        
        
        
            0 
        
        
            1042 
        
                    posted 16 years ago by svenito
            Detect if an object exists in an array or detect existance of a key in an object
        
        
        
            1 
        
        
            1109 
        
                    posted 16 years ago by quickredfox
            Adds a method to the Array object that lets you slice the array down to everything before the given value.
        
        
        
            0 
        
        
            891 
        
                    posted 16 years ago by segdeha
            hope you enjoy - thanks to Tom Duff (for implementation in C), Dean Edwards, and Nicholas Zakas for the idea
        
        
        
            0 
        
        
            913 
        
                    posted 16 years ago by jschilling
            Remove item (number or string) from array, using jQuery (method grep).
        
        
        
            3 
        
        
            15734 
        
                    posted 16 years ago by gustavopaes
            this function tells you whether or not the passed value is in the passed array
        
        
        
            1 
        
        
            1462 
        
                    posted 16 years ago by jlvallelonga
            remove(array) --> array
Array.remove(a) simply removes all the items in the passed in array from the current scope array.  Good for bulk operations.
        
        
        
            0 
        
        
            1248 
        
                    posted 17 years ago by kouphax
            You can find a string as an array row value.
Ex:
arr=['abcde','mdleo']
arr.find('dbd') -> array['abcde']
arr.find('akdowewo') -> array[] (empty)
        
        
        
            0 
        
        
            1445 
        
                    posted 17 years ago by tonic
            This function will sort an array of DOM elements in order of the DOM position.  Useful when using calls such as $$("img.L,img.M") which doesn;t return a sorted element array.
It uses prototype but you can replace the Prototype.Browser stuff with a...
        
        
        
            0 
        
        
            1598 
        
                    posted 17 years ago by kouphax