How to delete an array in an object in Javascript? For example I want to delete:
RandomObject.array = [];
So that when I use RandomObject in ways such as copying it into another object, the array is not included.
How to delete an array in an object in Javascript? For example I want to delete:
RandomObject.array = [];
So that when I use RandomObject in ways such as copying it into another object, the array is not included.
You need to use the delete
operator:
delete RandomObject.array;
Snippet Demo to show how it works:
var RandomObject = {};
RandomObject.array = [];
console.log(RandomObject);
delete RandomObject.array;
console.log(RandomObject);