how to convert json values in comma separated string using javascript

后端 未结 8 784
情话喂你
情话喂你 2021-01-18 06:29

I have following JSON string :

8条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 07:16

    You could add brackets to the string, parse the string (JSON.parse) and map (Array#map) the property and the join (Array#join) the result.

    var string = '{"name":"Marine Lines","location_id":3},{"name":"Ghatkopar","location_id":2}',
        array = JSON.parse('[' + string + ']'),
        result = array.map(function (a) { return a.location_id; }).join();
    
    console.log(result);

提交回复
热议问题