HexagonJS
Edit Page
List
A list collection that wraps standard JavaScript Arrays. Best reserved for cases where you are doing a lot of array mutation. In most cases a normal JavaScript Array should suffice.
Examples
// create an empty list
var list = new hx.List;

list.add(2);
list.add(4);
list.add(6);

// will log 3
console.log(list.size);

// remove an item from the list by position
list.delete(1);

// will log [2, 6]
console.log(list.values());

// remove the an item from the list by value
list.remove(6);

// will log [2]
console.log(list.values());

// removes everything from the list
list.clear();

// create a list prefilled with some values
list = new hx.List([1, 1, 2, 3, 3, 3, 4, 4, 5, 6]);

// remove all the 3's from the list
list.removeAll(3);

// will log [1, 1, 2, 4, 4, 5, 6]
console.log(list.values());

// will log false
console.log(list.has(3));

// will log true
console.log(list.has(4));

// get a value by position. this will log 4
console.log(list.get(3));
Api
Prototypes
hx.Listdeprecated
Deprecated
Deprecated in favour of using standard JS Arrays
A wrapper around standard JavaScript Arrays, with methods for adding and removing items.
Constructors
hx.ListarrayArray
Arguments
arrayArray
An array containing the values to initialise the list with
Properties
sizeNumber
The current size of the list
Methods
additemAnyList
Adds an object to the list. Returns this List for chaining.
Arguments
itemAny
The item to add.
Returns
List
This list for chaining
clearList
Removes all items from the list, resulting in an empty list with size 0. Returns this List for chaining.
Returns
List
This list for chaining
deleteindexNumberBoolean
Removes an entry from the list by position. Returns true if an item was removed, false otherwise.
Arguments
indexNumber
The index to remove.
Returns
entriesArray
Returns the items in the list as an array.
Returns
forEachfFunctionthisArgObject
Calls the function supplied for each item in the list. Returns this list for chaining.
Arguments
fvalueAny
The function that should be called for each item.
Arguments
valueAny
The value being considered from the list.
thisArg
A parameter which lets you supply the 'this' context to be used when calling f. The default is to use this List.
getindexNumberAny
Gets an item by position.
Arguments
indexNumber
A 0 based index which should be between 0 and list.size (exclusive). If the index is out of this range, then undefined will be returned.
Returns
Any
hasvalueAnyBoolean
Checks if the list contains a value. Returns true if the value is in the list, false otherwise.
Arguments
valueAny
The value to look for in the list.
Returns
True if the value is in the list
removevalueAnyBoolean
Removes the first occurrence of a value from the list. Returns true if a value was removed, false otherwise.
Arguments
valueAny
The value to remove from the list.
Returns
True if the value was removed
removeAllvalueAnyNumber
Removes all occurrences of a value from the list. Returns the number of items removed.
Arguments
valueAny
The value to remove from the list.
Returns
valuesArray
Returns the items in the list as an array - does the same as entries().
Returns