Reputation: 131
Is there a way to consistently exctract city names from strings that look like this:
{"id":25,"title":"Buenos Aires"}
{"id":26,"title":"Chicago"}
I was thinking about starting from 3 rd character from the end and then stopping at second quotation mark but I didnt find the way to do it.
Upvotes: 0
Views: 96
Reputation: 4180
The data is JSON formatted, you can decode it to js objects directly
var a = JSON.parse('{"id":25,"title":"Buenos Aires"}'),
b = JSON.parse('{"id":26,"title":"Chicago"}');
console.log(a.title); // prints Buenos Aires
console.log(b.title); // prints Chicago
Upvotes: 2