how to convert json values in comma separated string using javascript

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

I have following JSON string :

8条回答
  •  鱼传尺愫
    2021-01-18 07:19

    Simple:

    var data = [{"name":"Marine Lines","location_id":3},{"name":"Ghatkopar","location_id":2}]
    var result = data.map(function(val) {
      return val.location_id;
    }).join(',');
    
    console.log(result)

    I assume you wanted a string, hence the .join(','), if you want an array simply remove that part.

提交回复
热议问题