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.

asked Nov 28, 2014 at 20:08
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.

answered Nov 28, 2014 at 20:11
Sign up to request clarification or add additional context in comments.

2 Comments

What is there is only values. like var movies = ["Iron Man","Super Man"]. How to covert this
Simply movies.join(", ")

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.