Welcome To Snipplr


Everyone's Recent JavaScript Snippets Tagged array



« Prev 1 2 3
  1. FAV

    forEach. How to break?

    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...
    JavaScript 9 views posted 4 years ago by Waltem
  2. FAV

    Remove an item from array using UnderscoreJS

    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)....
    JavaScript 15 views posted 4 years ago by Balamir
  3. FAV

    delete Operator don’t impact the length of Array in JavaScript

    delete Operator don’t impact the length of Array in JavaScript
    JavaScript saved by 3 people 5 views posted 4 years ago by ursdeep
  4. FAV

    Method to determine if all values in an array are the same.

    Usage: var a = ['a','a','a']; var b = a.AllValuesSame(): //true var a ['1','1','2']; var b = a.AllValuesSame(); //false
    JavaScript 11 views posted 6 years ago by uberdragon
  5. FAV

    javascript array examples

    javascript arrays up and down
    JavaScript saved by 4 people 12 views posted 7 years ago by kutyadog
  6. FAV

    Remove duplicate itens from an array

    Original by dvdrtrgn
    JavaScript 5 views posted 7 years ago by guilhermehn
  7. FAV

    Generic List in Javascript

    The closest to a generic List in javascript. When calling constructor - new List(Module) - add model in constructor parameter
    JavaScript 3 views posted 7 years ago by mikkeldamm
  8. FAV

    Using call to invoke an anonymous function

    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...
    JavaScript 2 views posted 7 years ago by hellowouter
  9. FAV

    Using Math.min and Math.max for an array

    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...
    JavaScript 6 views posted 7 years ago by hellowouter
  10. FAV

    Array shuffle without bias

    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"...
    JavaScript 4 views posted 8 years ago by devnull69
  11. FAV

    Optional function arguments/parameters by using associative array

    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...
    JavaScript 5 views posted 8 years ago by coprolit
  12. FAV

    Convert PHP array into Javascript Array

    JavaScript 4 views posted 8 years ago by dato
  13. FAV

    IE7 Array indexOf() fix

    source: http://stellapower.net/content/javascript-support-and-arrayindexof-ie/<br> source: http://www.robsearles.com/2010/03/11/ie-7-indexof-replacement/
    JavaScript 3 views posted 8 years ago by shabith
  14. FAV

    switch elements index

    JavaScript 0 views posted 8 years ago by neilking
  15. FAV

    getting an objects key values

    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...
    JavaScript saved by 4 people 5 views posted 9 years ago by iroybot
  16. FAV

    getting an objects key values

    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...
    JavaScript 4 views posted 9 years ago by iroybot
  17. FAV

    Page-like structured array to HTML

    All glory to the ml function.
    JavaScript 1 views posted 9 years ago by pablo_PXL
  18. FAV

    javascript in_array

    Quick and easy javascript in_array function. It's not perfect, but if you need something quick, this is it.
    JavaScript saved by 2 people 3 views posted 9 years ago by cornellsteven
  19. FAV

    Array to SELECT

    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 = {...
    JavaScript 2 views posted 9 years ago by nomada
  20. FAV

    Remove Duplicate Values from Array

    Simple function that filters out any duplicate items in an array.
    JavaScript saved by 21 people 22 views posted 9 years ago by Nettuts
  21. FAV

    [JS] php print_r-like

    /*Coded by Alessio Delmonti - www.tecnocrazia.com */
    JavaScript saved by 1 person 2 views posted 9 years ago by Mosaic
  22. FAV

    [JS] Find key from value

    /*Coded by Alessio Delmonti - www.tecnocrazia.com*/
    JavaScript 3 views posted 9 years ago by Mosaic
  23. FAV

    Check for Array-ness

    JavaScript saved by 2 people 1 views posted 9 years ago by ionutzp
  24. FAV

    Удаление дубликатов из массива

    JavaScript 2 views posted 9 years ago by nuwak
  25. FAV

    Javascript remove item from array

    Simply pass in array name and the value of the item you want to remove
    JavaScript saved by 1 person 3 views posted 9 years ago by myke
  26. FAV

    sort strings (that contain umlauts)

    JavaScript 1 views posted 9 years ago by freder
  27. FAV

    add leading zeros

    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.
    JavaScript saved by 3 people 1 views posted 9 years ago by DADU
  28. FAV

    Unique array in JavaScript

    Thanks to the original author.
    JavaScript saved by 2 people 1 views posted 9 years ago by riddla
  29. FAV

    js get site scripts, create array

    JavaScript 0 views posted 9 years ago by brandonjp
  30. FAV

    output an array without for or while loop

    JavaScript 3 views posted 9 years ago by hand4ever
« Prev 1 2 3