Currently I am saving an array of objects to a local storage which is the settings and then I get or query or get it from local storage and I use index to assign the values like .
Currently I am assigning values using index like this.userSettings.jobSearchFilter.jobs[0].values;
, is there other way to change the setting structure or access the values from the array of object using fieldname instead of index.
so this.market should be equal to jobs.market.values , something like that
Thanks.
#ts code
this.userSettings = JSON.parse(localStorage.getItem('settings'));
if(this.userSettings.jobSearchFilter && this.userSettings.jobSearchFilter.jobs.length > 0){
this.market= this.userSettings.jobSearchFilter.jobs[0].values;
this.fund= this.userSettings.jobSearchFilter.jobs[1]?.values;
this.developmentlead= this.userSettings.jobSearchFilter.jobs[2]?.values;
this.developmentaccountant = this.userSettings.jobSearchFilter.jobs[3]?.values;
}
#array of objects that is being saved to local storage
this.userSettings = {
jobSearchFilter:{
...this.userSettings.jobSearchFilter,
jobs: [
{
type:'market',
values:settings.filter
},
{
type:'fund',
values:settings.fundFilter
},
{
type:'developmentLead',
values:settings.developmentLeadFilter
}
],
}
}
#sample query settings from local storage
[
{
"type": "market",
"values": [
{
"id": 503,
"description": "Atlanta",
}
]
},
{
"type": "fund",
"values": [
{
"id": 53,
"description": "11Atlanta",
}
]
},
{
"type": "developmentLead",
"values": [
{
"id": 533,
"description": "Atlant1",
}
]
},
{
"type": "developmentAccountant",
"values": null
},
]