Welcome To Snipplr


Everyone's Recent JavaScript Snippets Tagged array



« Prev 1 2 3
This code is used to get the unique values of an array.
0 13872 posted 4 years ago by jlustre
Array.prototype.forEach You can't break forEach. So use "some" or "every". Array.prototype.some some is pretty much the same as forEach but it break when the callback returns true. Array.prototype.every every is almost identical to some except i...
0 1093 posted 9 years ago by Waltem
Using underscore.js, you could combine .findWhere with .without Although, since you are creating a new array in this case anyway, you could simply use _.filter or the native Array.prototype.filter function (just like shown in the other question)....
0 3813 posted 9 years ago by Balamir
delete Operator don’t impact the length of Array in JavaScript
1 1102 posted 9 years ago by ursdeep
Usage: var a = ['a','a','a']; var b = a.AllValuesSame(): //true var a ['1','1','2']; var b = a.AllValuesSame(); //false
0 2546 posted 11 years ago by uberdragon
javascript arrays up and down
2 778 posted 12 years ago by kutyadog
Original by dvdrtrgn
0 1017 posted 12 years ago by guilhermehn
The closest to a generic List in javascript. When calling constructor - new List(Module) - add model in constructor parameter
0 831 posted 12 years ago by mikkeldamm
In this purely constructed example, we create anonymous function and use call to invoke it on every object in an array. The main purpose of the anonymous function here is to add a print function to every object, which is able to print the right index...
0 937 posted 12 years ago by hellowouter
Clever usage of apply allows you to use built-ins functions for some tasks that otherwise probably would have been written by looping over the array values. As an example here we are going to use Math.max/Math.min to find out the maximum/minimum valu...
0 1326 posted 12 years ago by hellowouter
The usual way to shuffle an array uses the .sort() method with Math.round(Math.random())-0.5 This solution is highly biased based on the sort algorithm used by the browsers. A sort comparison operation has to fulfill the condition "if a>b then b<a"...
0 738 posted 12 years ago by devnull69
By not being limited to provide certain arguments/parameters in right order when calling a function, makes the function more versatile and easier to extend without breaking old code (e.g. calls to the function). One solution is to pass an associati...
0 989 posted 12 years ago by coprolit
source: http://stellapower.net/content/javascript-support-and-arrayindexof-ie/<br> source: http://www.robsearles.com/2010/03/11/ie-7-indexof-replacement/
0 643 posted 13 years ago by shabith
0 582 posted 13 years ago by neilking
I wanted to pass a form submission (array) as a JSON object to another function. Some form field were created with JS, to identify them their names have been concatenated with unique IDs, etc. In order to access values of that JSON obj I needed to...
1 814 posted 13 years ago by iroybot
I wanted to pass a form submission (array) as a JSON object to another function. Some form field were created with JS, to identify them their names have been concatenated with unique IDs, etc. In order to access values of that JSON obj I needed to...
0 943 posted 13 years ago by iroybot
All glory to the ml function.
0 766 posted 13 years ago by pablo_PXL
Quick and easy javascript in_array function. It's not perfect, but if you need something quick, this is it.
1 644 posted 13 years ago by cornellsteven
This function automates the creation of the <OPTION>s of a <SELECT> element. It's ideal for your AJAX apps when you create display elements using Javascript It accepts to different kind of arrays: An array of key:values… var arrDirs = {...
0 666 posted 13 years ago by nomada
Simple function that filters out any duplicate items in an array.
7 1608 posted 13 years ago by Nettuts
/*Coded by Alessio Delmonti - www.tecnocrazia.com */
1 671 posted 14 years ago by Mosaic
/*Coded by Alessio Delmonti - www.tecnocrazia.com*/
0 643 posted 14 years ago by Mosaic
1 597 posted 14 years ago by ionutzp
Simply pass in array name and the value of the item you want to remove
1 980 posted 14 years ago by myke
This JavaScript code snippet checks each integer in an array. If necessary, one or more leading zeros are added to an integer. Note that each integer becomes a string.
1 743 posted 14 years ago by DADU
Thanks to the original author.
1 764 posted 14 years ago by riddla
« Prev 1 2 3