Answers for "REMOVE ELEMNTS FORM ANY PART OF THE ARRAY IN ANGULAR"

0

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" }] 

[]
Posted by: Guest on July-22-2021

Code answers related to "REMOVE ELEMNTS FORM ANY PART OF THE ARRAY IN ANGULAR"

Browse Popular Code Answers by Language