Turn properties of object into a comma-separated list?

前端 未结 10 1872
-上瘾入骨i
-上瘾入骨i 2021-02-01 02:42

I have an object like this:

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

I want:



        
10条回答
  •  孤城傲影
    2021-02-01 03:18

    You might want to try this library - Underscore.js. It gives you really helpful methods and works across browsers.

    Here you can do it like this -

    _.values(person).join(",")
    

    or

    _.values(person).join("|")
    

提交回复
热议问题