There are more options, you can make use of Set:
const data = {
"data": [
{
"id": 5,
"created": "2021-01-04T03:50:03.458+05:30"
},
{
"id": 7,
"created": "2021-01-04T03:50:03.469+05:30"
},
{
"id": 8,
"created": "2021-01-04T03:50:03.474+05:30"
}
]
};
const ids = data.data.map(e => e.id);
const setIds = new Set(ids);
expect(ids.length).to.equal(setIds.size);
Set will always contain only unique values, so if you don't have unique ids in the original data structure, the set object will have fewer elements.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…