#Array
DESCRIPTION
General
Installation
npm install eden-array
Usage
var array = require('eden-array');
Methods
clone
array clone( [2, 3, 4, 5] );
Clones an array
Parameters
- [2, 3, 4, 5] - array to be cloned
Returns
array
Example
Code
var list = [2, 3, 4, 5];
array().clone(list);
Outputs
'2, 3, 4, 5'
combine
object combine( ['key2', 'key3', 'key1', 'key5'], [1, 2, 3, 4] );
Combines a list of keys and values into an object
Parameters
-
['key2', 'key3', 'key1', 'key5'] - first array (list of keys)
-
[1, 2, 3, 4] - second array (lists of values)
Returns
object
Example
Code
var keys = ['key2', 'key3', 'key1', 'key5'];
var values = [1, 2, 3, 4];
array().combine(keys, values);
Outputs
key2, 1
key3, 2
key1, 3
key5, 4
concat
this concat( [1,2,3,4], [5, 6] );
Concats arrays into one
Parameters
- [1,2,3,4],[5, 6] - array[,array..](2 or more arrays are being concat)
Returns
this
Example
Code
var list = [1,2,3,4], argument = [5, 6];
array().concat(list, argument);
Outputs
'1,2,3,4,5,6'
each
bool each( [3, 4, 5, 6], function(key, value) );
Custom for each loop that handles scopes and extra arguments
Parameters
-
[3, 4, 5, 6] - array
-
function(key, value) - function
Returns
bool
Example
Code
var list = [3, 4, 5, 6], function(key, value);
array().each(list, function(key, value));
list.hasOwnProperty(key);
value;
Outputs
true
3
implode
string implode(Array, Mixed, Boolis.has, Array, String);
Returns true if the array has given value
Parameters
-
array
-
mixed
-
boolis.has - = function(data, value) {Argument Testingis.argument()test(1, 'array')test(1, 'mixed');turn data.indexOf(value) !== -1;*Join array elements with a string
-
array
-
string
Returns
string
Example
Code
var list = ['z','x','c'];
var delimeter = ('-');
array().implode(list, delimeter);
Outputs
'z-x-c'
isEmpty
bool isEmpty([]);
Check if data is array @param array @return bool
Parameters
- [] - array is empty
Returns
bool
Example
Code
var list = [3, 4, 5, 6];
var list1 = [];
array().isEmpty(list);
array().isEmpty(list1);
Outputs
false
true
keys
array keys( [3, 4, 5, 6] );
Returns a list of keys
Parameters
- [3, 4, 5, 6] - array
Returns
array
Example
Code
var list = [3, 4, 5, 6];
var keys = array().key(list);
array().keys(list);
array().size(keys);
Outputs
['0','1','2','3']
4
lastIndexOf
number lastIndexOf( [2, 3, 4, 5], 2 );
Returns the last index of where in the array the value is found
Parameters
-
[2, 3, 4, 5] - array
-
2 - mixed (specified value in the list of array)
Returns
number
Example
Code
var list = [2, 3, 4, 5];
array().lastIndexOf(list, 2);
Outputs
0
map
array map( [3, 4, 5, 6], function(key, value), [mixed[,mixed..]] );
Custom map loop that handles scopes and extra arguments
Parameters
-
[3, 4, 5, 6] - array
-
function(key, value) - function
-
[mixed[,mixed..]]
Returns
array
Example
Code
var list = [3, 4, 5, 6];
array().map(list, function(key, value));
return value + 1;
list[1];
list;
Outputs
5
[4,5,6,7]
natsort
object natsort( ['a', 'c', 'b'] );
Sorts array by natural sort
Parameters
- ['a', 'c', 'b'] - object
Returns
object
Example
Code
var list = ['a', 'b', 'c'];
array().natsort(list);
Outputs
'a,b,c'
pop
mixed pop( [1, 2, 3, 4] );
Pops array from the stack
Parameters
- [1, 2, 3, 4] - array
Returns
mixed
Example
Code
var list = [1, 2, 3, 4];
array().pop(list);
Outputs
4
push
array push( [1, 2, 3, 4], [5, 6] );
Pushes array into the stack
Parameters
-
[1, 2, 3, 4] - array
-
[5, 6] - mixed[,mixed..]
Returns
array
Example
Code
var list = [1, 2, 3, 4], argument = [5, 6]
array().push(list, argument);
Outputs
'1,2,3,4,5,6'
reverse
array reverse( ['a','b','c'] );
Reverses the array
Parameters
- ['a','b','c'] - array
Returns
array
Example
Code
var list = ['a','b','c'];
array().reverse(list);
Outputs
'c,b,a'
splice
array splice(Array, Num, Num, Mixed[,mixed..]);
Picks from chosen slice and rconturns a new array @param array @param num @param [num] @return array is.slice = function(data) { Argument Testing is.argument() est(1, 'array') est(2, 'int') est(3, 'int', 'undefined'); r args = Array.prototype.slice.apply(arguments); gs.shift(); turn data.slice.apply(data, args); * Adds/removes items to/from an array, and returns the removed item(s)
Parameters
-
array
-
num
-
num
-
mixed[,mixed..]
Returns
array
Example
Code
var list = [1,2,3,4], argument = (2, 3)
array().splice(list, argument);
Outputs
4
sort
array sort( ['a', 'c', 'b'], [function] );
Sorts an array
Parameters
-
['a', 'c', 'b'] - array
-
[function] - optional
Returns
array
Example
Code
var list = ['c','b','a'];
array().sort(list);
Outputs
'a,b,c'
size
number size( [2, 3, 4, 5] );
Returns the array size
Parameters
- [2, 3, 4, 5] - array
Returns
number
Example
Code
var list = [2, 3, 4, 5];
array().size(list);
Outputs
4
toQuery
string toQuery( [2, 3, 4, 5], [string] );
Converts array to query string
Parameters
-
[2, 3, 4, 5] - string
-
[string] - optional
Returns
string
Example
Code
var list = [2,3,4,5];
array().toQuery(list);
Outputs
'0=2&1=3&2=4&3=5'
toString
string toString( [2,3,4,5] );
Converts array to string
Parameters
Returns
string
Example
Code
var list = [2,3,4,5];
array().toString(list);
Outputs
'[2,3,4,5]'
unshift
array unshift( [1,2,3,4,5], 7 );
Unshifts array into the stack
Parameters
-
[1,2,3,4,5] - array
-
7 - mixed[,mixed..](new value to be added in the stack)
Returns
array
Example
Code
var list = [1, 2, 3, 4, 5];
var newList = array().unshift(list, 7);
newList.shift();
newList;
Outputs
7
[7, 1, 2, 3, 4, 5]
values
array values( [2, 3, 4, 5] );
Returns a list of values
Parameters
- array
Returns
array
Example
Code
var list = [2, 3, 4, 5]
array().values(list);
Outputs
2, 3, 4, 5