Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[JavaScript] Create array of unique property values from an array of objects

const a = [
      {'id': 1, 'name': 'Max'},
      {'id': 2, 'name': 'Tom'},
      {'id': 3, 'name': 'Max'},
      {'id': 4, 'name': 'Max'}
    ];

let r = [...new Set(a.map(u => u.name))] // result ["Max", "Tom"]

Leave a Reply

Your email address will not be published. Required fields are marked *