Skip to content

marcusvi200/list-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ListArray - Version 0.2.0

Browser Support

Chrome Firefox Safari Opera Edge
Latest âś” Latest âś” Latest âś” Latest âś” Latest âś”

Example

See a simple example!

How to use

Instantiating a ListArray

var listArray = new ListArray();

Add an object to the list

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};

let result = listArray.push(element);

result returns {uid: 1, name: 1, value: {name: "Edy", age: 27, country: "Brazil"}}

Add an object by assignment

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};

listArray.array = element;

result returns [{uid: 1, name: 1, value: {name: "Edy", age: 27, country: "Brazil"}}]

Duplicate an object

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element); 

let result = listArray.duplicate(1);

result returns {uid: 2, name: 2, value: {name: "Edy", age: 27, country: "Brazil"}}

Calls a function for each ListArray element

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element); 

listArray.forEach((value, name, uid){
    alert(`Value: ${value} | Name: ${name} | UID: ${uid}`);
});

NO returns

Returns the value of the first element in a ListArray that pass a test

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element); 

let result = listArray.find((value) =>{
    return value.name === "Edy";
});

result returns {'name': 'Edy', 'age': 27, 'country': 'Brazil'}

Link to another ListArray

var listArrayBought = new ListArray("bought");
let elementBought = {'idBought': 1, 'idUser': 25};
listArrayBought.push(elementBought);

var listArrayUser = new ListArray("user");
let elementUser = {'id': 25, 'name': 'Marcus Vinicius', 'country': 'Brazil'};
listArrayUser.push(elementUser);

let bondBOUGHT_USER = listArrayBought.bond(listArrayUser, (bought, user) => {
    return bought.idUser === user.id;
});

let result = bondBOUGHT_USER.array;

result returns [{uid: 1, name: 1, value: {bought: {value: {'idBought': 1, 'idUser': 25}}, user: [uid: 1, name: 1, value: {'id': 25, 'name': 'Marcus Vinicius', 'country': 'Brazil'}]}]

Copy the value and name of the current ListArray into the ListArray entered

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element); 

var listArrayCopy = new ListArray();
listArray.copyTo(1, listArrayCopy);

let result = listArrayCopy.array;

result returns [{'name': 'Edy', 'age': 27, 'country': 'Brazil'}]

Concatenate two or more ListArray

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

var listArray2 = new ListArray();
let element2 = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray2.push(element2);

var listArray3 = new ListArray();
let element3 = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray3.push(element3);

let result = listArray.concat(listArray2,listArray3);

result returns [{uid: 1, name: 1, value: {'name': 'Edy', 'age': 27, 'country': 'Brazil'}},{uid: 2, name: 2, value: {'name': 'Edy', 'age': 27, 'country': 'Brazil'}},{uid: 3, name: 3, value: {'name': 'Edy', 'age': 27, 'country': 'Brazil'}}]

Replace an object already inserted in the list

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);
let newElement = {'name': 'Marcus', 'age': 28, 'country': 'Brazil'};

listArray.replace(1, newElement);

NO returns

Get the list size

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

let result = listArray.getSize();

result returns 1

Get an object by UID

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

let result = listArray.getByUID(1);

result returns [{uid: 1, name: 1, value: {name: "Edy", age: 27, country: "Brazil"}}]

Get all elements in String

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

let result = listArray.toString();

result returns "[{"uid":1,"name":1,"value":{"name":"Edy","age":27,"country":"Brazil"}}]"

Get a String object by UID

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

let result = listArray.toString(1);

result returns "{"name":"Edy","age":27,"country":"Brazil"}"

Get all elements in JSON

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

let result = listArray.toJSON();

result returns [{uid: 1, name: 1, value: {name: "Edy", age: 27, country: "Brazil"}}]

Get a JSON object by UID

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

let result = listArray.toJSON(1);

result returns {name: "Edy", age: 27, country: "Brazil"}

Replace the name and value of a list object

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

listArray.replaceNameValue(1, 'Register-1', newElement);

result returns [{uid: 1, name: "Register-1", value: {name: "Marcus", age: 28, country: "Brazil"}}]

Get an object by Name

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element, "Register-1");

let result = listArray.getByName('Register-1');

result returns [{uid: 1, name: "Register-1", value: {'name': 'Edy', 'age': 27, 'country': 'Brazil'}}]

Delete an object from the list with the UID

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

let result = listArray.deleteUID(1);

result returns []

Delete all ListArray content

var listArray = new ListArray();
let element = {'name': 'Edy', 'age': 27, 'country': 'Brazil'};
listArray.push(element);

let result = listArray.clearAll();

result returns []

About

Save objects in a list

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published