identical-list
v1.1.1
Published
An advanced list class, manage element by id
Downloads
15
Maintainers
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"}]