Turn properties of object into a comma-separated list?

前端 未结 10 1690
-上瘾入骨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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 03:15

    var arr = [
        {
            key_1: "A",
            key_2: "1"
        },
        {
            key_1: "B",
            key_2: "2"
        },
        {
            key_1: "C",
            key_2: "3"
        }
    ];
    
    var CSVOf_arr = arr.map((item) => { return item.key_1 }).join(',')
    
    console.log('Comma seprated values of arr', CSVOf_arr)
    

    OUTPUT: A,B,C

提交回复
热议问题