
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
A library for array functions in Array.prototype
npm install array-lib
const arrayLib = require("array-lib");
clone
deep copy an array
let arr = [1,2,3];
let clone_arr = arr.clone();
print
arr.print();//=> [1,2,3]
"hello".print();// =>hello
(123).print();//=>123
{a:12}.print();//=>{a:12}
max
Retrun max value from array
arr.max().print();
maxIndex
Returns index of max value in array:
arr.maxIndex().print()
remove
Removes element at the specified position
arr.remove(0);
arr.print()//=> [2,3]
removeVal
Removes first or all values from array
let a = [1,2,3,4,4,5,5];
let remove_all_elements = true;
a.removeVal(4,remove_all_elements);
a.print();//=> [1,2,3,5,5];
count
Count how much times a element is in an array
let b = ["a","b","b","c","b"];
console.log(b.count("b"));//=> 3
replace
Replace elements in array
let c = [1,2,3,3,3,4,6,6,9];
c.replace(3,"d");
c.print();//=>[1,2,"d","d","d",4,6,6,9]
addUp
Add up all numbers in array
let d = [1,2,3,4,5];
d.addUp().print();//=> 15
matrix
Create a 2d array
let arr = Array.matrix(2,3,"fill")
arr.print();
//=>
//[
// [ 'fill', 'fill', 'fill' ],
// [ 'fill', 'fill', 'fill' ]
// ]
vector
Create an array
let arr = Array.vector(6,"fill");
arr.print();//=> ['fill', 'fill', 'fill','fill', 'fill', 'fill']
toArray
Create an array from a string
"hello ,world ,how ,are ,you".toArray().print();//=>
//[ 'hello', 'world', 'how', 'are', 'you' ]
multiplyMatrices
let b = [[1,2],[3,4]]
b.multiplyMatrices([[1,4],[6,7]]).print()
//=>[ [ 13, 18 ], [ 27, 40 ] ]
isMatrix
check if an array is a 2d matrix
let matrix = [
[0,1,2],
[3,4,5],
[6,7,8]
];
matrix.isMatrix().print()// => true
avrage
get Avrage from array
[1,2,3,4,5].avrage().print();//=> 3
pos
return first position of element in an array
[1,2,3,4,5].pos(4).print();//=>3
[1,2,3,4,5].pos(9).print();//=>false
getAllPos
Get all positions of element in array
let arr = [1,3,4,4,8,7,5,3,4];
b.getAllPos(4).print();//=> [2,3,8]
shuffle
shuffle an array
[1,2,3,4,5,6,7,8,9].shuffle().print();
//=> [ 7, 2, 9, 1, 6, 8, 3, 5, 4 ]
range
A function to create flexibly-numbered lists of integers
Array.range(10);
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Array.range(1, 11);
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Array.range(0, 30, 5);
//=> [0, 5, 10, 15, 20, 25]
Array.range(0, -10, -1);
//=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
Array.range(0);
//=> []
without
Returns a copy of the array with all instances of the values removed.
let a = [1,2,3,1,2,31,2,31,1,2,3,]
let b = a.without(1,2);
b.print();
//=>[ 3, 31, 31, 3 ]
FAQs
A library for array functions in Array.prototype
The npm package array-lib receives a total of 37 weekly downloads. As such, array-lib popularity was classified as not popular.
We found that array-lib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.