Here is an array that needs to be stored in local storage when the DOM is created.
this.headers.push(
{
text: "Name",
align: "center",
sortable: true,
value: "name",
align: "start",
},
{
text: "Company",
align: "center",
sortable: true,
value: "company",
align: "start",
},
{
text: "Phone",
align: "center",
sortable: true,
value: "phone",
align: "start",
}
)
The value of each object should be stored in local storage under the key name el_columns
. I have attempted it like this:
this.headersList.forEach((element) => {
localStorage.setItem(
"el_columns",
JSON.stringify(element.value)
);
});
The code above works but only stores one value, which ends up being the last object's value - phone
. The desired output should be something like ['name', 'company', 'phone']
.