JSFiddle - React, Tailwind, and code Playground
by David Thomas
JavaScript
function removeByPropertyEquals(haystack, needleProp, needleVal) {
haystack.forEach(function (obj, index) {
if (obj[needleProp] === needleVal) {
return index;
}
});
return -1;
}
var id = 3,
array = [{
id: '1',
title: 'test'
}, {
id: '2',
title: 'tes2'
}, {
id: '3',
title: 'tes3'
}];
console.log( array );
array.splice(removeByPropertyEquals(array, 'id', '3'), 1);
console.log( array);