Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an object like this:

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

I want:

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?

question from:https://stackoverflow.com/questions/26732123/turn-properties-of-object-into-a-comma-separated-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
100 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use this one-liner in modern browsers

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...