Is there an easy way to convert a Javascript Object into "name": "Fred", "value": "Blue" style pairs?

I'm positive this question must have been covered before, but I can quite find it. So.... I have an object like so Object name: Fred lastname: Jones city: Los Angeles I'd like to use Javascript to convert it to a string that looks like this: //Do want this [ {"name": "name", "value": "Fred"}, {"name": "lastname", "value": "Jones"}, {"name": "city", "value": "Los Angeles"} ] All of the examples I've found use JSON.parse() to get a result that looks like this (which I don't want): //Don't want this [ {"name": "Fred", "lastname": "Jones", "city": "Los Angeles"} ] I'm working with another developer who says this is how Jquery parses objects (EDIT- he's using $serializeArray(), so perhaps JQuery has a method to help me with this. Any ideas would be most welcome. Thanks!
What is the advantage of the format you want? In short, you just need to split key-value pairs into (name-key, value-value) objects. Should be simple with a simple loop.

以上就是Is there an easy way to convert a Javascript Object into "name": "Fred", "value": "Blue" style pairs?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏