1
I was trying to remove an element from an array, and since I’m trying to learn a little 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... Is there a better way to join (chain) these two functions? There is a better way to do this (from the point of view of functional programming)?
Thank you very much.
what are the two functions you want to join ? splice and findIndex ?
– 13dev
Exact, or at least was the initial idea (before the @Rgio consideration)
– Eder Prado