I am using jquery and I have a JSON object array and I want to convert into a string like below. I found that there is a method called "JSON.stringify" but i have no idea how to use it in my case.
var movies = [{"Title":"Iron Man"},{"Title":"Super Man"},{"Title":"Spider Man"}];
What i want is the following sting.
var movielist = 'Iron Man, Super Man,Spider Man';
Thanks in advance.
asked Nov 28, 2014 at 20:08
Daybreaker
1,0476 gold badges22 silver badges43 bronze badges
-
This has close relationship to another SO post. This may be what your looking for: stackoverflow.com/questions/24432269/…Tez Wingfield– Tez Wingfield2014年11月28日 20:12:29 +00:00Commented Nov 28, 2014 at 20:12
1 Answer 1
var movielist=$.map(movies, function(o) { return o["Title"]; }).join(", ");
Assuming you want spaces after the commas that is. If you omit the ", " it'll just use commas.
answered Nov 28, 2014 at 20:11
CupawnTae
14.7k3 gold badges31 silver badges62 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Daybreaker
What is there is only values. like var movies = ["Iron Man","Super Man"]. How to covert this
CupawnTae
Simply
movies.join(", ")lang-js