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"]
Tag: object
[JavaScript] Create date object from date string yyyyMMdd
Using regex, you can simply reorder the parts of your date string to create a compatible ISO 8601 date string which is accepted by the new Date()
constructor.
const date_string = "20220101"
const oDate = new Date(date_string.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3'))
console.log(oDate.toUTCString())
[CAP] Get ID for newly created entry in a table defined with aspect cuid
https://cap.cloud.sap/docs/cds/common#aspect-cuid
https://cap.cloud.sap/docs/node.js/databases#insertresult-beta
const result = await INSERT(payload).into(table)
const newEntries = [...result]
console.log("New ID: " + newEntries[0].ID)
[JavaScript] Create date object from date string dd.MM.yyyy
Using regex, you can simply reorder the parts of your date string to create a compatible ISO 8601 date string which is accepted by the new Date()
constructor.
const date_string = "01.01.2022"
const oDate = new Date(date_string.replace(/(.*)\.(.*)\.(.*)/, '$3-$2-$1'))
console.log(oDate.toUTCString())