0.3.0 • Published 7 years ago
iterables-js v0.3.0
//Define a class
class Example {
constructor(
public id: number,
public name: string
){}
}
//Create a collection that identifies objects by its 'id'
let collection = new Collection<Example>('id');
//Adding a new element
let obj = new Example(1, 'Example1');
collection.add(obj);
//Adding elements array
let array = [new Example(2, 'Example2')];
collection.addElements(array);
//Get element by index
let obj = collection.get(0); //Return obj
//Get element by key
let obj = collection.getByKey('1') //Return obj
//Removing element
collection.remove(obj);
//Check if collection contains an element
collection.contains(obj);
//Get collection size
let size = collection.size();
//Iterate
for(element of collection.elements())
{
//
}