Programming/JavaScript/Array extensions

From Skypher

Jump to: navigation, search

Main Page
├─▼Programming
│ ├─▼JavaScript
│ │ ├─▷JSSh
│ │ ├─○JavaScriptStringEncode()
│ │ ├─○serialize()
│ │ ├─○visualize()
│ │ ├─○stackDump()
│ │ ├─○errorHandler()
│ │ └─●Array extensions
│ ├─▷ASP
│ └─○Chimera code
└─▷Hacking

Contents


Array extensions

A number of functions that extend the existing Array API.

Source code: [http://skypher.com/SkyLined/JS/arrayExtensions.js]
Examples: [http://skypher.com/SkyLined/JS/arrayExtensions.html]

Array_contains(oArray, xNeedle)

Searches the array "oArray" for an element with the value "xNeedle". Return true if any one elements of the array contain this value. It works of regular arrays and associative arrays and uses "===" compare.

Array_uniqueElements(aArray)

Removes any duplicate elements from the array "aArray", so it only contains unique elements and sorts it. If you have a fragmented array, it will be made contiguous, if you have an associative array, only the numbered elements are affected.

Array_randomize(aArray)

Randomizes the order of the elements of the array "aArray". If you have a fragmented array, it will be made contiguous, if you have an associative array, only the numbered elements are randomized.

Array_randomIndex(aArray)

Returns a random index for an element of the array "aArray". Will return the number of a random numbered element between 0 and "aArray.length". If you have a fragmented or associative array, you should consider using Array_randomElementName, which is slower but returns only the numbers of defined numbered elements as well as the names of named elements. Will return "0" for an empty array.

Array_randomElement(aArray)

Returns a random element of the array "aArray". Will return the value of a random numbered element between 0 and "aArray.length". If you have a fragmented or associative array, you should consider using Array_randomNamedElement, which is slower but returns only defined numbered elements as well as named elements. Will return "undefined" for an empty array.

Array_randomElementName(oArray)

Returns the name of a random element of the array "oArray". Works on regular and associative arrays. For numbered elements, the number is returned as a string. It will return only the names of elements that are enumerable. Will return "undefined" for an empty array.

Array_randomNamedElement(oArray)

Returns the value of a random named element of the array "oArray". Works on regular and associative arrays. It will return only the values of elements that are enumerable. If you have a non-fragmented, non-associative array, you should consider using Array_randomElement, which is faster. Will return "undefined" for an empty array.

Personal tools