Hello I am trying to get a grasp on underscore.js
i have a json file as follows:
[
{
"name":"rocky",
"last-updated": "Yesterday",
"age":"32"
},
{
"name":"annie",
"last-updated": "Today",
"age":"31"
}
]
And a javascript function:
function getNames() {
var users = $.ajax({
url : "users.json",
async : false
});
var names = _.map(JSON.parse(users.responseText),
function(user) {
return user.name
});
return names;
}
It works fine on IE but on Chrome, it throws me:
Uncaught SyntaxError: Unexpected token ,
on this line:
var names = _.map(JSON.parse(users.responseText),function(user) {return user.name});
As far as I know this error is because of trying to parse object not the JSON string. Am i right? How do I solve this? It works on IE?
Thank you!