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 1253 posted 8 months 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 213 posted 5 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 888 posted 5 years ago by Balamir
delete Operator don’t impact the length of Array in JavaScript
1 203 posted 5 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 407 posted 7 years ago by uberdragon
javascript arrays up and down
2 144 posted 8 years ago by kutyadog
Original by dvdrtrgn
0 253 posted 8 years ago by guilhermehn
The closest to a generic List in javascript. When calling constructor - new List(Module) - add model in constructor parameter
0 175 posted 8 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 202 posted 8 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 257 posted 8 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 122 posted 8 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 220 posted 8 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 116 posted 9 years ago by shabith
0 93 posted 9 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 157 posted 9 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 161 posted 9 years ago by iroybot
All glory to the ml function.
0 142 posted 9 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 118 posted 9 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 133 posted 9 years ago by nomada
Simple function that filters out any duplicate items in an array.
7 338 posted 9 years ago by Nettuts
/*Coded by Alessio Delmonti - www.tecnocrazia.com */
1 115 posted 10 years ago by Mosaic
/*Coded by Alessio Delmonti - www.tecnocrazia.com*/
0 102 posted 10 years ago by Mosaic
1 97 posted 10 years ago by ionutzp
Simply pass in array name and the value of the item you want to remove
1 178 posted 10 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 133 posted 10 years ago by DADU
Thanks to the original author.
1 142 posted 10 years ago by riddla
« Prev 1 2 3