EN
JavaScript - remove object from associative array
0
points
In this article, we would like to show you how to remove an object from an associative array in JavaScript.
By associative arrays in JavaScript, we can mean objects because they map keys (properties) to values.
To remove a property from an object in JavaScript, use the delete operator.
Practical example
In this example, we use the delete operator to remove name property from user object.
// ONLINE-RUNNER:browser;
const user = { name: 'Tom', age: 20 };
delete user['name'];
console.log(JSON.stringify(user)); // { "age": 20 }
Note:
Whendeleteoperator is applied to an index property of an Array, it will create an array with a missing index.
Note:
The
deleteoperator doesn't directly free the memory.