satya
satya

Reputation: 3560

How to get individual value from array using JavaScript/Angular.js

i have a array object which produce below output.

console.log('response',response);

response [{"id":"2","name":"subhra","pass":"12345","email":"[email protected]"}]

Here i need all individual value(email,id,pass,name) using JavaScript.Please help me to resolve this issue.

Upvotes: 0

Views: 17111

Answers (2)

gaurav bhavsar
gaurav bhavsar

Reputation: 2043

You can use angular.forEach

Working Plunker

Controller

$scope.response = [{"id":"2","name":"subhra","pass":"12345","email":"[email protected]"}]

angular.forEach($scope.response, function(item){
    $scope.Id = item.id; // id is in $scope.Id
    $scope.Name = item.name; // name is in $scope.Name
    $scope.Email = item.email; // email is in $scope.Email
    scope.Pass = item.pass;   // pass is in $scope.Pass
});

HTML

<body ng-controller="MainCtrl">
    <p> ID : {{Id}}</p>
    <p> Name : {{Name}}</p>
    <p> Pass : {{Pass}}</p>
    <p> email : {{Email}}</p>
</body>

Upvotes: 0

SVK
SVK

Reputation: 2197

Updated link

var data=[{"id":"2","name":"subhra","pass":"12345","email":"[email protected]"}];
console.log('response',data);

    console.log('response',data[0].id); //2
    console.log('response',data[0].name); //subhra
    console.log('response',data[0].pass); //12345
    console.log('response',data[0].email); //[email protected]

Upvotes: 1

Related Questions