Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  5] [ 6]  / answers: 1 / hits: 39365  / 8 Years ago, fri, october 14, 2016, 12:00:00

I have following JSON string :





{name:Marine Lines,location_id:3},{name:Ghatkopar,location_id:2}





I want location_id as



3,2


More From » json

 Answers
36

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.


[#60396] Wednesday, October 12, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxh

Total Points: 137
Total Questions: 100
Total Answers: 103

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;