-2

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.

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
leonylyner
  • 117
  • 2
  • 7

1 Answers1

3

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);
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252