Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  69] [ 5]  / answers: 1 / hits: 64827  / 11 Years ago, wed, january 29, 2014, 12:00:00

I have 1 array, one with a list of all my users with unique IDs. I have an object which contains contains a selected groups information. Part of that information is the owners ID. I'm trying to figure out, how do I get the users's information given the groups owner ID? For example, the student group object has an owner ID of 70, there's a user on my sites who's ID is 70...how do I match them up?



users: 
[ {
id: 68
name: mike
domain: i:0#.f|admembers|mike.ca
email: mike.ca
isAdmin: False
}, etc etc ]

selectedGroup: {
name: Students
id: 78
description:
owner: 70
ownerIsUser: True
}

More From » arrays

 Answers
35

You'll have to loop through users:



var i = users.length,
ownerData;

while(i--) {
if(selectedGroup.owner == users[i].id) {
ownerData = users[i];
break;
}
}


Or you could use Array.filter():



var ownerData = users.filter(function(user) {
return user.id === selectedGroup.owner;
})[0];

[#72862] Tuesday, January 28, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dayana

Total Points: 302
Total Questions: 102
Total Answers: 100

Location: Cayman Islands
Member since Fri, Mar 4, 2022
2 Years ago
;