我所拥有的:
{"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"}}我想要的:
{"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"}}我试过的是:
const filtered = _.uniqBy(authors, 'slug')
//result [], [], [], []有解决办法吗?
发布于 2022-09-26 11:27:34
如果这是存放函数,您应该尝试这样做,如果您不想有两个相同的作者:
const filtered = _.uniqBy(authors, 'name')发布于 2022-09-26 16:08:09
const uniqueTags = [];
authors.map((item) => {
var findItem = uniqueTags.find((x) => x.name === item.name);
if (!findItem) uniqueTags.push(item);
});https://stackoverflow.com/questions/73852721
复制相似问题