0

I have a json string:

arguments[0] = [{"one":"1","two":"1","three":"15","four":"esj","five":null,"six":"2015-10-15 00:00:00","seven":null},
{"one":"1","two":"1","three":"15","four":"esj","five":null,"six":"2015-10-15 00:00:00","seven":null},
{"one":"1","two":"1","three":"15","four":"esj","five":null,"six":"2015-10-15 00:00:00","seven":null, ...}] 

and I want to change it to the format like this:

[ '1', '1', '15', 'esj', null, '2015-10-15 00:00:00', null],
[ '1', '1', '15', 'esj', null, '2015-10-15 00:00:00', null],
[ '1', '1', '15', 'esj', null, '2015-10-15 00:00:00', null], etc...

how can I do it in jquery?

EDIT:

Using @Joseph the dreamer's answer I almost made it work, now I'm using:

return ["['"+arg.one+"'", "'"+arg.two+"'", "'"+arg.three+"'", "'"+arg.four+"'", "'"+arg.five+"'", "'"+arg.six+"']"]

and it produces me this:

[1,2,3,4,5,6],[1,2,3,4,5,6], etc 

which is fine, but I need to convert it later on to a string. How can I do that?

3
  • 1
    Use a basic for loop and build it yourself. Commented Oct 19, 2015 at 21:04
  • @Blazemonger can you tell me how to do it exactly? Commented Oct 19, 2015 at 21:16
  • Your question is confusing. First you ask only to convert json (or objects) to arrays and now you've amended your question to further ask how to convert it to strings (which could be another question, which would be a duplicate). Actually at the first revision your question was clear and well formatted to be useful (to get an upvote). Now it's ... confusing. :/ Commented Oct 20, 2015 at 0:03

1 Answer 1

2

No jQuery required actually. All you need is map.

var arr = arguments[0].map(function(arg){
  return [arg.one, arg.two, arg.three, arg.four, arg.five, arg.six, arg.seven];
});

Would have gone for Object.keys to loop through the keys, but order had to be preserved. Plus, I would discourage modifying arguments.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, I used your answer and I'm almost there, but I have one additional question - can you check my update to the main question?
@user3766930 JSON.stringify()

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.