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 11362 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 841 posted 8 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 3402 posted 8 years ago by Balamir
delete Operator don’t impact the length of Array in JavaScript
1 841 posted 8 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 2014 posted 10 years ago by uberdragon
javascript arrays up and down
2 580 posted 11 years ago by kutyadog
Original by dvdrtrgn
0 806 posted 11 years ago by guilhermehn
The closest to a generic List in javascript. When calling constructor - new List(Module) - add model in constructor parameter
0 615 posted 11 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 735 posted 11 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 1038 posted 11 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 537 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 789 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 479 posted 12 years ago by shabith
0 417 posted 12 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 614 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 724 posted 13 years ago by iroybot
All glory to the ml function.
0 599 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 481 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 497 posted 13 years ago by nomada
Simple function that filters out any duplicate items in an array.
7 1308 posted 13 years ago by Nettuts
/*Coded by Alessio Delmonti - www.tecnocrazia.com */
1 498 posted 13 years ago by Mosaic
/*Coded by Alessio Delmonti - www.tecnocrazia.com*/
0 455 posted 13 years ago by Mosaic
1 432 posted 13 years ago by ionutzp
Simply pass in array name and the value of the item you want to remove
1 745 posted 13 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 565 posted 13 years ago by DADU
Thanks to the original author.
1 574 posted 13 years ago by riddla
« Prev 1 2 3