angularjs - Javascript Object attribute with '-' doesn't work properly -
this question has answer here:
i have json response in following format.
{ "_meta" : { "next-person-id" : "1001", "totalpersons" : "1000" } }
i using angular's $http
service retrieve , trying access next-person-id
attribute in javascript following,
$http.get(url).then( function(response){ console.log(response._meta.next-person-id); } );
but next-person-id
in response undefined always. i'm able access totalpersons attribute. there problem getting attributes '-' character in javascript?
use bracket notation:
console.log(response._meta['next-person-id']);
a possible alternative change keys use underscores, _meta.next_person_id
work.
Comments
Post a Comment