How can I convert this
[{"party":"Abc"},{"party":"Pqr"},{"party":"jky"}]
to this
["Abc","Pqr","jky"]
via javascript
How can I convert this
[{"party":"Abc"},{"party":"Pqr"},{"party":"jky"}]
to this
["Abc","Pqr","jky"]
via javascript
I think you'd do something like.
var arr = [{"party":"Abc"},{"party":"Pqr"},{"party":"jky"}]
var arrString = arr.toString();
If it doesn't work try this. Let me know if either one worked for you.
var arrString = JSON.stringify(arr);
Are you trying to turn it into a string or an object array?
"party" is the object here
all i want is to get an array of the values
["Abc","Pqr","jky"]
try this then
var arrString = JSON.parse(arr);
instead of stringifying it
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hmm. We'll I'm working on storing objects arrays in local storage myself and trying to modify them as well when they are stored. I've been having some issues myself. When you have it as a string what does the console tell you?
Here is an array I created and stored it to a local storage variable called test.
function Person (name, age) {
this.name = name;
this.age = age;
}
var family = new Array();
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
family[3] = new Person("timmy", 6);
var fx = JSON.stringify(family);
localStorage.setItem("test", fx);
var x = JSON.parse(localStorage.getItem("test"));
for(i = 0; i < x.length; i++){
console.log(x.name);
}
the console reads out
alice
bob
michelle
timmy
I hope this helps
Hello Abhijeet.
We have provided answer via e-mail
Here is an array I created and stored it to a local storage variable called test.
function Person (name, age) {
this.name = name;
this.age = age;
}
var family = new Array();
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
family[3] = new Person("timmy", 6);
var fx = JSON.stringify(family);
localStorage.setItem("test", fx);
var x = JSON.parse(localStorage.getItem("test"));
for(i = 0; i < x.length; i++){
console.log(x.name);
}
the console reads out
alice
bob
michelle
timmy
I hope this helps