Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

locate and delete an object in an array

 // we have an array of objects, we want to remove one object using only the id property
var apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
 
// get index of object with id:37
var removeIndex = apps.map(function(item) { return item.id; }).indexOf(37);
 
// remove object
apps.splice(removeIndex, 1);
Comment

how to find and remove object from array in javascript

var id = 88;

for(var i = 0; i < data.length; i++) {
    if(data[i].id == id) {
        data.splice(i, 1);
        break;
    }
}
Comment

find object and remove in array

//remove object with id = 1 in an array
_.remove(array, (e) => {
	return e.id == 1
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: // Write a function that takes two strings (a and b) as arguments // If a contains b, append b to the beginning of a // If not, append it to the end // Return the concatenation 
Javascript :: traverse 2d array js 
Javascript :: find missing number array javascript 
Javascript :: console.log color terminal 
Javascript :: jquery confirm delete massege 
Javascript :: replace non alphanumeric javascript 
Javascript :: can immigrants vote in uk 
Javascript :: parse date do weekday 
Javascript :: javascript parse and validate json 
Javascript :: disable back button in react native 
Javascript :: ionic 4 get previous route 
Javascript :: how to create an invite discord.js 
Javascript :: turn nodelist into array 
Javascript :: change elements class javascript 
Javascript :: firebase get current user javascript 
Javascript :: node.js socket.io send data with handshake 
Javascript :: discord.js ticket system stackoverflow 
Javascript :: react setupproxy 
Javascript :: current date in javascript 
Javascript :: javascript to string 
Javascript :: javascript append to paragraph 
Javascript :: generate random 6 numbers in javascript 
Javascript :: ReferenceError: window is not defined 
Javascript :: how to square a value in javascript 
Javascript :: if json then parse 
Javascript :: fill array with random numbers javascript 
Javascript :: get id button clicked react 
Javascript :: angular lifecycle hooks 
Javascript :: first x characters of string javascript 
Javascript :: how to change react icon color 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =