identical-list

1.1.1 • Public • Published

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"}]

Package Sidebar

Install

npm i identical-list

Weekly Downloads

2

Version

1.1.1

License

ISC

Unpacked Size

67.1 kB

Total Files

9

Last publish

Collaborators

  • laituanmanh32