Answers for "how to remove item from array in javascript by using index"

36

javascript remove from array by index

//Remove specific value by index
array.splice(index, 1);
Posted by: Guest on May-06-2020
0

Remove element from array

const apps = [
  {id:1, name:'test1'}, 
  {id:2, name:'test2'},
  {id:3, name:'test3'}
]
//remove item with id=2
const itemToBeRemoved = {id:2, name:'test2'}
apps.splice(apps.findIndex(a => a.id === itemToBeRemoved.id) , 1)
//print result
console.log(apps)
Posted by: Guest on September-30-2021

Code answers related to "how to remove item from array in javascript by using index"

Code answers related to "Javascript"

Browse Popular Code Answers by Language