0

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.

8
  • you can simply store it in variable like var a=[{"id":"2","name":"subhra","pass":"12345","email":"[email protected]"}]; then access it like console.log(a[0].id); Commented Sep 25, 2015 at 10:59
  • Please could you explain your problem more clearly? Commented Sep 25, 2015 at 11:02
  • @ Ripun : No its showing undefined when i followed your way. Commented Sep 25, 2015 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. Commented Sep 25, 2015 at 11:11
  • 1
    Is your response a string? You might need to call JSON.parse(response) and then use the methods suggested above. Commented Sep 25, 2015 at 11:11

2 Answers 2

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

first store array of object in one variable i.e data. check updated link.
0

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.