0

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.

1

1 Answer 1

3
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.

2
  • What is there is only values. like var movies = ["Iron Man","Super Man"]. How to covert this Commented Nov 28, 2014 at 20:20
  • Simply movies.join(", ") Commented Nov 28, 2014 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.