In an AngularJS app, I have an object stored in data returned from $http that looks something like this:
[{"var1":"1","var2":"2","var3":"3"}]
I want to be able to get the value of "var2".
I thought this would be easy:
$scope.myObj = data;
$scope.myVar = $scope.myObj.var2; //$scope.myvar should "2"
Instead, $scope.myObj returns undefined
how can I access the value of var2?
datais array, if it is always of size 1 array then do$scope.myObj = data[0]console.log($scope.myvar)shows[object Object]and, in HTML,{{myVar}}displays[{"var1":"1","var2":"2","var3":"3"}]angular.isObject()returnedtrue. Please enter this as an answer and I will mark it as CORRECT!!