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.
In this example, we use the delete
operator to remove name
property from user
object.
xxxxxxxxxx
1
const user = { name: 'Tom', age: 20 };
2
3
delete user['name'];
4
5
console.log(JSON.stringify(user)); // { "age": 20 }
Note:
Whendelete
operator is applied to an index property of an Array, it will create an array with a missing index.
Note:
The
delete
operator doesn't directly free the memory.