ListControl


Use this control to work with arrays and list-objects. Using this control enables you to easily iterate over the items or perform simple collection-related actions.

Initialization

// With an array
const list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

const listControl = new ListControl(list);

// Or with an object
const list = {
    someKey: 'someValue',
    anotherKey: 'anotherValue',
};

const listControl = new ListControl(list);

.add()

Add an item to the list

// Add an item without a key
listControl.add(11);

// Add an item with a given key
listControl.add('yetAnotherValue', 'yetAnotherKey');

.all()

Get all items

.callback()

Iterate over the items.

listControl.callback((value, index, key) => {
    // Here we can use the `value`, `index` and `key` of the items
});

.first()

Get the first item of the list

.isEmpty()

Check if the list is empty

.length

Get the length of the list