Skip to content

ThePywon/locked-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

An array that can be completely locked from adding/removing elements on demand





Table of content





How to use?

Description

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

Import

Terminal

npm install @protagonists/locked-array

Node.js

const LockedArray = require("@protagonists/locked-array");


Example

Code:

// 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);

Output:

[ 'apple', 'orange', 'tomato' ]
[ 'apple', 'orange', 'tomato' ]






This is the bottom, there is nothing more.
Go back up?

About

Ever wanted readonly arrays?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published