Abhijeet Singh
Posts: 0
Joined: Thu May 08, 2014 5:54 pm

String Parsing

How can I convert this

[{"party":"Abc"},{"party":"Pqr"},{"party":"jky"}]

to this

["Abc","Pqr","jky"]

via javascript

sebastian
Posts: 1
Joined: Tue Oct 21, 2014 9:46 pm

String Parsing

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);

sebastian
Posts: 1
Joined: Tue Oct 21, 2014 9:46 pm

String Parsing

Are you trying to turn it into a string or an object array?

Abhijeet Singh
Posts: 0
Joined: Thu May 08, 2014 5:54 pm

String Parsing

"party" is the object here

all i want is to get an array of the values

["Abc","Pqr","jky"]

sebastian
Posts: 1
Joined: Tue Oct 21, 2014 9:46 pm

String Parsing

try this then

var arrString = JSON.parse(arr);

instead of stringifying it

Abhijeet Singh
Posts: 0
Joined: Thu May 08, 2014 5:54 pm

String Parsing

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

sebastian
Posts: 1
Joined: Tue Oct 21, 2014 9:46 pm

String Parsing

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?

sebastian
Posts: 1
Joined: Tue Oct 21, 2014 9:46 pm

String Parsing

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

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

String Parsing

Hello Abhijeet.
We have provided answer via e-mail

sebastian
Posts: 1
Joined: Tue Oct 21, 2014 9:46 pm

String Parsing

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

Return to “Issues”