accessing arrays

Published 1 week ago by Webiondev123

I have this array in angular

$scope.credentials.usergroups = data; //gets data from server How can I access this for specific values. I need to send to server?

this is data:

 console.log( $scope.credentials);

 output:

{usergroups: Array(1), title: "how to read the degree in ERD?", group_id: "1", date: Wed Nov 29 2017 00:00:00 GMT+0800 (U Peninsula Standard Time), file: "data:;base64,LyoNCk5hdmljYXQgTXlTUUwgRGF0YSBUcmFuc…zDQotLSAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tDQo="}
date
:
Wed Nov 29 2017 00:00:00 GMT+0800 (Malay Peninsula Standard Time)
__proto__
:
Object
file
:
"data:;base64,[garbage]
group_id
:
"1"
title
:
"how to read the degree in ERD?"
usergroups
:
Array(1)
0
:
{id: 1, name: "taskgroup", $$hashKey: "object:342"}
length
:
1
__proto__
:
Array(0)
__proto__
:
Object

Best Answer (As Selected By Webiondev123)
RamjithAp

If it's a single array access it like

var title = $scope.credentials.usergroups['title'];

If it has more than one array use for loop

for(var i=0;i<$scope.credentials.usergroups.length;i++){
console.log($scope.credentials.usergroups[i]['title']);
}
RamjithAp

If it's a single array access it like

var title = $scope.credentials.usergroups['title'];

If it has more than one array use for loop

for(var i=0;i<$scope.credentials.usergroups.length;i++){
console.log($scope.credentials.usergroups[i]['title']);
}
Webiondev123

Thanks

Please sign in or create an account to participate in this conversation.