I was trying to remove an element from an array, and since I'm trying to learn a bit more about functional programming, I tried to change the old way I used to do this.
const myArray = [
{id: 1, label: 'first'},
{id: 2, label: 'second'},
{id: 3, label: 'third'},
]
const itemToRemove = {
id: 2,
label: 'second'
}
myArray.splice(myArray.findIndex(item => {
return item.id == itemToRemove.id
}), 1)
console.log('->', JSON.stringify(myArray, null, 2))
My question ... Is there a better way to chain these two functions? Is there a better way to do this (from the point of view of functional programming)?
Thank you very much.