首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何合并用户项并显示在他的个人资料上?

如何合并用户项并显示在他的个人资料上?
EN

Stack Overflow用户
提问于 2022-09-26 10:19:02
回答 2查看 27关注 0票数 0

我所拥有的:

代码语言:javascript
复制
{"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"}}

我想要的:

代码语言:javascript
复制
{"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"}}

我试过的是:

代码语言:javascript
复制
const filtered = _.uniqBy(authors, 'slug')

//result [], [], [], []

有解决办法吗?

EN

回答 2

Stack Overflow用户

发布于 2022-09-26 11:27:34

如果这是存放函数,您应该尝试这样做,如果您不想有两个相同的作者:

代码语言:javascript
复制
const filtered = _.uniqBy(authors, 'name')
票数 1
EN

Stack Overflow用户

发布于 2022-09-26 16:08:09

代码语言:javascript
复制
const uniqueTags = [];
authors.map((item) => {
  var findItem = uniqueTags.find((x) => x.name === item.name);
  if (!findItem) uniqueTags.push(item);
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73852721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档