-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
  • 147,524
  • 33
  • 287
  • 271
leonylyner
  • 117
  • 1
  • 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
  • 160,666
  • 24
  • 190
  • 242