I have an array of objects that look like this
const data = [
{id: 1, locale: 'en'},
{id: 2, locale: 'nl'}
]
Now I'm trying to filter out the locale property in every item in the array (not delete it for good, just filter it out this once), so my data would ideally resemble this:
const data = [
{id: 1},
{id: 2}
]
Using a map function to spread out the properties, but I'm stuck as to how to continue with this.
this.translations.map(translation => {
return { ...translation }
})
You can use parameter destructuring to extract the locale and keep the other ones:
const data = [
{id: 1, locale: 'en'},
{id: 2, locale: 'nl'}
]
const withoutLocale = data.map(({locale, ...rest}) => rest)
console.log(withoutLocale)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With