我有一个看起来像这样的对象数组
const data = [
{id: 1, locale: 'en'},
{id: 2, locale: 'nl'}
]
现在我正在尝试过滤掉数组中每个项目的语言环境属性(不是永久删除它,只是过滤掉这一次),因此我的数据理想情况下类似于:
const data = [
{id: 1},
{id: 2}
]
我试过了
使用 map 函数来展开属性,但我不知道如何继续这样做。
this.translations.map(translation => { return { ...translation } })
最佳答案
您可以使用 parameter destructuring提取 locale
并保留其他的:
const data = [
{id: 1, locale: 'en'},
{id: 2, locale: 'nl'}
]
const withoutLocale = data.map(({locale, ...rest}) => rest)
console.log(withoutLocale)
关于javascript - 从数组中的多个对象过滤属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55123799/