[
Employee {
empId: 1000,
empName: 'John',
empSalary: 9123,
},
Employee {
empId: 1001,
empName: 'Doe',
empSalary: 10000,
},
Employee {
empId: 1002,
empName: 'Jason',
empSalary: 9812,
},
Employee {
empId: 1003,
empName: 'Jamie',
empSalary: 6661,
}
]
This is my array with set of objects. I want to take a user input and delete from the array based on ID. I've tried using splice but I keep getting errors.
var target = prompt("Enter id to delete:");
for(var i = 0; i < data.length; i++) {
if(data[i].empId === target) {
data.splice(i, 1);
break;
}
}
If someone can please help me out please do!