将对象的属性转换为逗号分隔的列表? [英] Turn properties of object into a comma-separated list?

查看:59
本文介绍了将对象的属性转换为逗号分隔的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的对象:

var person = {
  name: "John",
  surname: "Smith",
  phone: "253 689 4555"
}

我想要:

John,Smith,253 689 4555

有一些简单的方法吗?

Is there some easy way?

如果可能,能否请您提供我还可以定义分隔符的示例?

If possible, could you please provide an example where I can also define the separator?

推荐答案

您可以在现代浏览器中使用此单行代码

You can use this one-liner in modern browsers

Object.keys(person).map(function(k){return person[k]}).join(",");

这篇关于将对象的属性转换为逗号分隔的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆