Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

delete item from array of objects javascript

const apps = [
  {id:1, name:'Jon'}, 
  {id:2, name:'Dave'},
  {id:3, name:'Joe'}
]

//remove item with id=2
const itemToBeRemoved = {id:2, name:'Dave'}

apps.splice(apps.findIndex(a => a.id === itemToBeRemoved.id) , 1)

//print result
console.log(apps)
 Run code snippet
Comment

delete item from array of objects javascript

var removeByAttr = function(arr, attr, value){
    var i = arr.length;
    while(i--){
       if( arr[i] 
           && arr[i].hasOwnProperty(attr) 
           && (arguments.length > 2 && arr[i][attr] === value ) ){ 

           arr.splice(i,1);

       }
    }
    return arr;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to make popup modal in jquery with example 
Javascript :: loop through an array 
Javascript :: convert string to array with condition javascirpt 
Javascript :: react native time range picker 
Javascript :: launch json file for rust 
Javascript :: open window in same tab 
Javascript :: lazy loading by scroll vue 
Javascript :: node.js global variables 
Javascript :: document.createelement with id 
Javascript :: notify js 
Javascript :: liquid filter 
Javascript :: javascript benchmark 
Javascript :: js quote 
Javascript :: update data in sequelize 
Javascript :: react native charts 
Javascript :: padstart in javascript 
Javascript :: max array 
Javascript :: Importing From Export Default Module 
Javascript :: js then vs await 
Javascript :: short-circuit evaluation javascript 
Javascript :: how to check if a variable is true or false in javascript 
Javascript :: + operator javascript 
Javascript :: bot react message with custom emoji 
Javascript :: how to use switch case in javascript 
Javascript :: sails js 
Javascript :: search in javascript 
Javascript :: javascript expression interpolation 
Javascript :: What do "module.exports" and "exports.methods" mean in NodeJS / Express 
Javascript :: map function 
Javascript :: what is a blob in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =