I have populated an array like this:
`public IamanArray;
public MYARRAY(array: Array<any>)
{
this.localStorage.set('IamanArray',array);
}`
I need a simple way to access, let's say value at index [1] of this array. Is there a simple way to do it?
I have tried :
`this.localStorage.get('IamanArray[1]');`
but it won't work.
Any suggestion? Thanks!
you would need to extract the item first and then get the item:
public extraData(): any {
let iamanArray = JSON.parse(localStorage.getItem('IamanArray'));
return iamanArray[1];
}
Also your set should be as follows:
public MYARRAY(array: Array<any>) {
localStorage.setItem('IamanArray', array);
}
Small error, it should be getItem:
let arr = localStorage.getItem('IamanArray');
let value = arr[0];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.