Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

identical-list

laituanmanh3210ISC1.1.1

An advanced list class, manage element by id

list, identical, list, identical

readme

Installation

  • npm install identical-list

Usage

How to use List class

var List = require("identical-list");

var array = [{id: 1, msg: "Hi"}, {id: 2, msg: "Hello"}, {id: 10, msg: "Im Manh"}];
let list = new List(array);
console.log(list.asArray()); // [{id: 1, msg: "Hi"}, {id: 2, msg: "Hello"}]
console.log(list.get(10)); // {id: 10, msg: "Im Manh"}

Add new element to list

list.add({id: 5, msg: "I love javascript"});
console.log(list.asArray());
// [{id: 1, msg: "Hi"}, {id: 2, msg: "Hello"}, {id: 10, msg: "Im Manh"}, {id: 5, msg: "I love javascript"}]

Update an element of list

let updatedObject = {id: 1, msg: "How are you?"}

list.add(updatedObject);
console.log(list.asArray());
// [{id: 1, msg: "How are you?"}, {id: 2, msg: "Hello"}, {id: 10, msg: "Im Manh"}, {id: 5, msg: "I love javascript"}]

Remove an element of list

list.deleteId(10);
console.log(list.asArray()); //[{id: 1, msg: "Hi"}, {id: 2, msg: "Hello"}]