Arrays
Members
-
add :Array.<T>
-
Add Element
Example
var a = [1,2]; a.add(3); console.log(a); // [1,2,3] var b = [0,9]; console.log(b.add(2)); // [0,9,2]
-
addAll :Array.<any>
Add another array
-
Add another array to current array
Example
var a = [0,1]; var b = ['a','b']; console.log(b.addAll(a)); // ['a','b',0,1] var c = ['z',10]; c.addAll(b); console.log(c); // ['z',10,'a','b',0,1] var d = ['last']: d.addAll(a,b,c); console.log(d); // ['last','a','b',0,1]
-
compact :Array.<T>
-
Removes null and undefined elements from the array, turning it into a dense array. Returns self for chaining purposes
-
contains :boolean
-
Check array contains string/any
Example
alert([1, 2, 3].contains(2)); // => true alert([1, 2, 3].contains('2')); // => false
-
deleteAt :Array.<T>
-
Deletes the element at the specified index, returning that element, or undefined if the index is out of range. A negative index is counted from the end of the array, where -1 corresponds to the last element. Returns self for chaining purposes.
Example
var a = ["ant", "bat", "cat", "dog"] a.deleteAt(2) // => "cat" a // => ["ant", "bat", "dog"] a.deleteAt(99) // => undefined (because index 99 not found) if(a.deleteAt(1)) console.log('item with index 1 removed') // conditional
-
each
-
same as Array
['forEach'] -
exists :boolean
-
Check element index exists
Example
['a','b'].exists(1); //true ['a','b'].exists(4); //false
-
first :Array.<T>
-
Returns the first element, or the first n elements, of the array. If the array is empty, requesting one element returns undefined , and requesting multiple elements returns an empty array.
Example
var a = [ "q", "r", "s", "t" ] a.first() // => "q" a.first(2) // => ["q", "r"]
-
hapusItemDariArrayLain :function
-
Remove array item from other arrays
-
hasIndex :boolean
-
Check if array offset (index) exists
Example
alert([{},'a','x'].hasIndex(2)); // => true - array has offset 2 is 'x' alert([{},'a','x'].hasIndex(3)); // => false
-
isEmpty :boolean
-
Returns true if self contains no elements.
- See:
-
- Array
.length
- Array
-
last :Array.<T>
-
Returns the last element(s) of self. If the array is empty, returns undefined if only one element requested.
Example
var a = [ "w", "x", "y", "z" ] a.last() // => "z" a.last(2) // => ["y", "z"]
-
move :function
-
Move item to another index
-
random :function
-
Pick 1 random array element
-
range :Array.<any>
-
Get element in range from array
Example
const arr = [1, 2, 3, 4, 5]; console.log(arr.range(1, 3));
-
removeEmpties :Array.<T>
-
Remove null, empty string, or undefined values
-
shuffle :Array.<T>
-
Randomize array elements
Example
alert([1,2,3,4,5].shuffle())
-
split_chunks :function
-
split array to chunks
-
trim :Array.<string>
-
trim array of strings
-
unique :function
-
Unique Array
Example
var duplicate = [1,2,1,2,3,4,5,6]; var unique = duplicate.unique(); // [1,2,3,4,5,6]
-
uniqueObjectKey :function
-
Unique array of objects by key
-
uniqueStringArray :function
-
Unique string array case insensitive but keep one case sensitive result
Example
console.log(['James', 'james', 'bob', 'JaMeS', 'Bob'].uniqueStringArray()); // ["JaMeS", "Bob"]
-
unset :Array.<T>
-
Unset element value from array
Example
var arr = ['a','b','c']; arr.unset('c'); console.log(arr); // ['a','b']