Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript unique grouped arrays

let user = {
  id: 12345,
  aCaption: { teams: ["111", "222", "444"] },
  bCaptain: { teams: ["444", "222", "111", "444"] }
};

let userA = user.aCaptain?.teams ?? []; // 111, 222, 444
let userB = user.bCaptain?.teams ?? []; // 444, 222, 111, 444

let userAllUniqueTeams = [...new Set([...userA, ...userB])]; // 111, 222, 444
 
PREVIOUS NEXT
Tagged: #javascript #unique #grouped #arrays
ADD COMMENT
Topic
Name
5+7 =