#Array
DESCRIPTION
npm install eden-array
var array = require('eden-array');
array clone( [2, 3, 4, 5] );
Clones an array
- [2, 3, 4, 5] - array to be cloned
array
var list = [2, 3, 4, 5];
array().clone(list);
'2, 3, 4, 5'
object combine( ['key2', 'key3', 'key1', 'key5'], [1, 2, 3, 4] );
Combines a list of keys and values into an object
-
['key2', 'key3', 'key1', 'key5'] - first array (list of keys)
-
[1, 2, 3, 4] - second array (lists of values)
object
var keys = ['key2', 'key3', 'key1', 'key5'];
var values = [1, 2, 3, 4];
array().combine(keys, values);
key2, 1
key3, 2
key1, 3
key5, 4
this concat( [1,2,3,4], [5, 6] );
Concats arrays into one
- [1,2,3,4],[5, 6] - array[,array..](2 or more arrays are being concat)
this
var list = [1,2,3,4], argument = [5, 6];
array().concat(list, argument);
'1,2,3,4,5,6'
bool each( [3, 4, 5, 6], function(key, value) );
Custom for each loop that handles scopes and extra arguments
-
[3, 4, 5, 6] - array
-
function(key, value) - function
bool
var list = [3, 4, 5, 6], function(key, value);
array().each(list, function(key, value));
list.hasOwnProperty(key);
value;
true
3
string implode(Array, Mixed, Boolis.has, Array, String);
Returns true if the array has given value
-
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
string
var list = ['z','x','c'];
var delimeter = ('-');
array().implode(list, delimeter);
'z-x-c'
bool isEmpty([]);
Check if data is array @param array @return bool
- [] - array is empty
bool
var list = [3, 4, 5, 6];
var list1 = [];
array().isEmpty(list);
array().isEmpty(list1);
false
true
array keys( [3, 4, 5, 6] );
Returns a list of keys
- [3, 4, 5, 6] - array
array
var list = [3, 4, 5, 6];
var keys = array().key(list);
array().keys(list);
array().size(keys);
['0','1','2','3']
4
number lastIndexOf( [2, 3, 4, 5], 2 );
Returns the last index of where in the array the value is found
-
[2, 3, 4, 5] - array
-
2 - mixed (specified value in the list of array)
number
var list = [2, 3, 4, 5];
array().lastIndexOf(list, 2);
0
array map( [3, 4, 5, 6], function(key, value), [mixed[,mixed..]] );
Custom map loop that handles scopes and extra arguments
-
[3, 4, 5, 6] - array
-
function(key, value) - function
-
[mixed[,mixed..]]
array
var list = [3, 4, 5, 6];
array().map(list, function(key, value));
return value + 1;
list[1];
list;
5
[4,5,6,7]
object natsort( ['a', 'c', 'b'] );
Sorts array by natural sort
- ['a', 'c', 'b'] - object
object
var list = ['a', 'b', 'c'];
array().natsort(list);
'a,b,c'
mixed pop( [1, 2, 3, 4] );
Pops array from the stack
- [1, 2, 3, 4] - array
mixed
var list = [1, 2, 3, 4];
array().pop(list);
4
array push( [1, 2, 3, 4], [5, 6] );
Pushes array into the stack
-
[1, 2, 3, 4] - array
-
[5, 6] - mixed[,mixed..]
array
var list = [1, 2, 3, 4], argument = [5, 6]
array().push(list, argument);
'1,2,3,4,5,6'
array reverse( ['a','b','c'] );
Reverses the array
- ['a','b','c'] - array
array
var list = ['a','b','c'];
array().reverse(list);
'c,b,a'
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)
-
array
-
num
-
num
-
mixed[,mixed..]
array
var list = [1,2,3,4], argument = (2, 3)
array().splice(list, argument);
4
array sort( ['a', 'c', 'b'], [function] );
Sorts an array
-
['a', 'c', 'b'] - array
-
[function] - optional
array
var list = ['c','b','a'];
array().sort(list);
'a,b,c'
number size( [2, 3, 4, 5] );
Returns the array size
- [2, 3, 4, 5] - array
number
var list = [2, 3, 4, 5];
array().size(list);
4
string toQuery( [2, 3, 4, 5], [string] );
Converts array to query string
-
[2, 3, 4, 5] - string
-
[string] - optional
string
var list = [2,3,4,5];
array().toQuery(list);
'0=2&1=3&2=4&3=5'
string toString( [2,3,4,5] );
Converts array to string
string
var list = [2,3,4,5];
array().toString(list);
'[2,3,4,5]'
array unshift( [1,2,3,4,5], 7 );
Unshifts array into the stack
-
[1,2,3,4,5] - array
-
7 - mixed[,mixed..](new value to be added in the stack)
array
var list = [1, 2, 3, 4, 5];
var newList = array().unshift(list, 7);
newList.shift();
newList;
7
[7, 1, 2, 3, 4, 5]
array values( [2, 3, 4, 5] );
Returns a list of values
- array
array
var list = [2, 3, 4, 5]
array().values(list);
2, 3, 4, 5