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 21649 posted 5 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 3529 posted 10 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 6561 posted 10 years ago by Balamir
delete Operator don’t impact the length of Array in JavaScript
1 3642 posted 10 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 4636 posted 12 years ago by uberdragon
javascript arrays up and down
2 1468 posted 13 years ago by kutyadog
Original by dvdrtrgn
0 1673 posted 13 years ago by guilhermehn
The closest to a generic List in javascript. When calling constructor - new List(Module) - add model in constructor parameter
0 1306 posted 13 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 2473 posted 13 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 2172 posted 13 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 1206 posted 13 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 1668 posted 13 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 1072 posted 14 years ago by shabith
0 1015 posted 14 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 1607 posted 14 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 1487 posted 14 years ago by iroybot
All glory to the ml function.
0 1278 posted 14 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 1049 posted 14 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 1168 posted 14 years ago by nomada
Simple function that filters out any duplicate items in an array.
7 3245 posted 15 years ago by Nettuts
/*Coded by Alessio Delmonti - www.tecnocrazia.com */
1 1101 posted 15 years ago by Mosaic
/*Coded by Alessio Delmonti - www.tecnocrazia.com*/
0 1113 posted 15 years ago by Mosaic
1 1005 posted 15 years ago by ionutzp
Simply pass in array name and the value of the item you want to remove
1 1587 posted 15 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 1180 posted 15 years ago by DADU
Thanks to the original author.
1 1250 posted 15 years ago by riddla
« Prev 1 2 3