Rocket Array 2.1 is 33.6% lighter and until 20 times more faster than Rocket Array 1.5 and is designed to be simplest way possible to manipulate your array
$ npm install rocket-array
Initialize
require("rocket-array"); //for node.js integration
//example for this doc
const myArray = [
"this",
"is",
"hello",
"world",
{
name: "alice",
infos: {
level: 18
}
},
{
name: "bob",
infos: {
level: 50
}
},
{
name: "other",
infos: {
level: 2
}
},
5,
10,
2,
"this",
"is",
"my",
"world"
];
const number = 2;
const recurrentData = myArray.recurrent(number);
//return [[{number: 2, name: "this"}, {number: 2, name: "is"}]]
Parameter | Type | Required | Default |
---|---|---|---|
Number | Number | No | 1 |
const type = "number";
const onlyTypeString = myArray.only(type);
//return [5, 10, 2];
Parameter | Type | Required | Default |
---|---|---|---|
Type | String | Yes | "string" |
myArray.removeRecurrents();
const data = "me";
myArray.pushBefore(data);
Parameter | Type | Required | Default |
---|---|---|---|
Type | All | Yes | No Default Value |
const position = 1,
numberElement = 2;
//numberElement defines how much data should be deleted after the position
myArray.remove(position, numberElement);
Parameter | Type | Required | Default |
---|---|---|---|
Position | Number | Yes | No Default Value |
numberElement | Number | No | 1 |
myArray.find({
regex: /is/,
morethan: 5,
lessthan: 5,
equal: 10,
type: "string"
});
myArray.findJSON({
regex: /as/,
type: "string",
morethan: 5,
lessthan: 5,
equal: 10,
where: "infos.level"
});
Parameter | Type | Required | Default |
---|---|---|---|
equal | All | No | undefined |
regex | Regex | No | false |
type | String | No | false |
morethan | Number | No | false |
lessthan | Number | No | false |
where (just for .findJSON()) | String | Yes | No Default Value |
//the "remove" functions do not change your Array
myArray = myArray.findAndRemove({
regex: /is/,
lessthan: 10,
morethan: 9,
equal: 10,
type: "string"
});
//the "remove" functions do not change your Array
myArray = myArray.findAndRemoveInJSON({
where: "name",
regex: /is/,
lessthan: 10,
morethan: 9,
type: "string"
});
Parameter | Type | Required | Default |
---|---|---|---|
equal | All | No | undefined |
regex | Regex | No | false |
type | String | No | false |
morethan | Number | No | false |
lessthan | Number | No | false |
where (just for .findJSON()) | String | Yes | No Default Value |
const local = myArray.toString(); // toString() = JSON.stringify
const params = [
{
where: "name",
regex: /as/
},
{
where: "infos.level",
morethan: 5
}
];
myArray.mufindJSON(params);
Parameter | Type | Required | Default |
---|---|---|---|
Params | Array | Yes | No Default Value |
const params = [
{
where: "name",
regex: /as/
},
{
where: "infos.level",
morethan: 5
}
];
myArray.mufindAndRemoveInJSON(params);
Parameter | Type | Required | Default |
---|---|---|---|
Params | Array | Yes | No Default Value |