Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.

share|improve this question
    
you can simply store it in variable like var a=[{"id":"2","name":"subhra","pass":"12345","email":"subh@gm‌​ail.com"}]; then access it like console.log(a[0].id); – Ripun Sep 25 '15 at 10:59
    
Please could you explain your problem more clearly? – Callum Linington Sep 25 '15 at 11:02
    
@ Ripun : No its showing undefined when i followed your way. – satya Sep 25 '15 at 11:10
    
@CallumLinington : I have a object which output is given in my post.I need to extract all individual value from it and store in different variable. – satya Sep 25 '15 at 11:11
1  
Is your response a string? You might need to call JSON.parse(response) and then use the methods suggested above. – Johan Sep 25 '15 at 11:11

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]
share|improve this answer
    
@ SVK : No its showing undefined. – satya Sep 25 '15 at 11:15
    
first store array of object in one variable i.e data. check updated link. – SVK Sep 25 '15 at 11:16

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>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.