REMOVE ELEMNTS FORM ANY PART OF THE ARRAY IN ANGULAR
function RemoveElementFromObjectArray(key: number) {
objectArray.forEach((value,index)=>{
if(value.id==key) objectArray.splice(index,1);
});
}
RemoveElementFromObjectArray(6);
RemoveElementFromObjectArray(5);
RemoveElementFromObjectArray(4);
RemoveElementFromObjectArray(3);
RemoveElementFromObjectArray(2);
RemoveElementFromObjectArray(1);
[{ "id": 1, "name": "Angular" },
{ "id": 2, "name": "Typescript" },
{ "id": 3, "name": "Javascript" },
{ "id": 4, "name": "HTML" },
{ "id": 5, "name": "Java" }]
[LOG]:
[{ "id": 1, "name": "Angular" },
{ "id": 2, "name": "Typescript" },
{ "id": 3, "name": "Javascript" },
{ "id": 4, "name": "HTML" }]
[LOG]:
[{ "id": 1, "name": "Angular" },
{ "id": 2, "name": "Typescript" },
{ "id": 3, "name": "Javascript" }]
[LOG]: [{ "id": 1, "name": "Angular" },
{ "id": 2, "name": "Typescript" }]
[LOG]: [{ "id": 1, "name": "Angular" }]
[]