An array that can be completely locked from adding/removing elements on demand
This is a simple array package that can prevent users from modifying the array itself
Elements within it can still be modified and accessed as normal
npm install @protagonists/locked-array
const LockedArray = require("@protagonists/locked-array");
// Imports
const LockedArray = require("@protagonists/locked-array");
// Create LockedArray instance
const fruits = new LockedArray(["apple", "orange"]);
// Add "tomato" in the array
fruits.add("tomato");
// Lock the array
fruits.lock();
// Log the array's value
console.log(fruits.value);
// try to add element to the direct value
fruits.value.push("banana");
// Log the array's value
console.log(fruits.value);
[ 'apple', 'orange', 'tomato' ]
[ 'apple', 'orange', 'tomato' ]