What i have:
{"name": "author-1", "slug": {"_type": "slug", "current": "author-1-slug"}}
{"name": "author-2", "slug": {"_type": "slug", "current": "author-2-slug"}}
{"name": "author-1", "slug": {"_type": "slug", "current": "author-1-slug"}}
{"name": "author-3", "slug": {"_type": "slug", "current": "author-3-slug"}}
What i want:
{"name": "author-2", "slug": {"_type": "slug", "current": "author-2-slug"}}
{"name": "author-1", "slug": {"_type": "slug", "current": "author-1-slug"}}
{"name": "author-3", "slug": {"_type": "slug", "current": "author-3-slug"}}
What i tried:
const filtered = _.uniqBy(authors, 'slug')
//result [], [], [], []
Any solution?
If this is lodash function, you shoud try like this, if you don't want to have 2 same authors:
const filtered = _.uniqBy(authors, 'name')
const uniqueTags = []; authors.map((item) => { var findItem = uniqueTags.find((x) => x.name === item.name); if (!findItem) uniqueTags.push(item); });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.