This is a simple Local Storage Array for Nativescript, integrated by application-settings module. With this you can add some array in localstorage.
- get all data or by index
- insert
- update
- remove
- drop
Nativescript 8 or newer
- Put localstorage_array.js in App Directory.
- And Import the localstorage_array.js like this :
import { LSget, LSinsert, LSupdate, LSremove, LSdrop } from '../localstorage_array'
you can adjust that Import path if you want
With this, you can get all data or get data by index.
LSget(index, distinct, xkey)
Params | Type | Default Value | Description |
---|---|---|---|
index | number | null | For get data by index. If you want get all data, you can fill null for this field. |
distinct | boolean | false | Set TRUE if you want hide duplicate data in your array. |
xkey | String | lsakc | Your xkey. |
// you can adjust that Import path
import { LSget } from '../localstorage_array'
let a = LSget();
if(a.success){
console.log(a.data);
} else {
console.log(a.message);
}
For insert new data.
LSinsert(data, xkey)
Params | Type | Default Value | Description |
---|---|---|---|
data | json or array | [] | Add your data here, data must be in json format. |
xkey | String | lsakc | You can make new your xkey here. |
// you can adjust that Import path
import { LSinsert } from '../localstorage_array'
let mydata = {
"name" : "kang cahya",
"hobby" : "hiking",
"color" : "blue"
};
let a = LSinsert(mydata);
if(a.success){
console.log(a.data);
} else {
console.log(a.message);
}
For update data by index.
LSupdate(data, index, xkey)
Params | Type | Default Value | Description |
---|---|---|---|
data | json | {} | Add your data here, data must be in json format. |
index | number | 0 | This is a key for update your data. |
xkey | String | lsakc | Your xkey. |
// you can adjust that Import path
import { LSupdate } from '../localstorage_array'
let mydata = {
"name" : "kang cahya",
"hobby" : "hiking",
"color" : "blue"
};
let a = LSupdate(mydata, 1);
if(a.success){
console.log(a.data);
} else {
console.log(a.message);
}
For delete data by index.
LSremove(index, xkey)
Params | Type | Default Value | Description |
---|---|---|---|
index | number | 0 | This is a key for delete your data. |
xkey | String | lsakc | Your xkey. |
// you can adjust that Import path
import { LSremove } from '../localstorage_array'
let a = LSremove(3);
if(a.success){
console.log(a.message);
} else {
console.log(a.message);
}
With this, you can delete all data in xkey.
LSdrop(xkey)
Params | Type | Default Value | Description |
---|---|---|---|
xkey | String | lsakc | Your xkey. |
// you can adjust that Import path
import { LSdrop } from '../localstorage_array'
let a = LSdrop("your_xkey");
if(a.success){
console.log(a.message);
} else {
console.log(a.message);
}