Tom Rider
Tom Rider

Reputation: 2815

Removing array in javascript

How we can remove an array entry from :

            var a = [],b = [],c = [],d = [];
            var multi = {
                a: a, b: b, c: c, d: d
            };

Means if i want to remove a array from multi . What should i do?

Upvotes: 2

Views: 92

Answers (4)

Blaster
Blaster

Reputation: 9080

Use delete keyword:

delete multi.a

Example:

var a = [], b = [], c = [], d = [];
var multi = { a: a, b: b, c: c, d: d };

delete multi.a;
console.log(multi);

Result:

Object
  b: Array[0]
  c: Array[0]
  d: Array[0]

Docs:

The delete operator removes a property from an object.

Upvotes: 1

xdazz
xdazz

Reputation: 160953

var a = [],b = [],c = [],d = [];
var multi = {
   a: a, b: b, c: c, d: d
};
delete multi.a;
console.log(multi);

Upvotes: 0

Rich O'Kelly
Rich O'Kelly

Reputation: 41767

You can delete it:

delete multi.a

Upvotes: 0

Quentin
Quentin

Reputation: 944430

To remove a property of an object, delete it.

delete multi.a

It doesn't matter what the value of the property is (it can be an array or anything else).

The variable a will still contain a reference to the same array though. If you want to get rid of it entirely, you have to overwrite that variable or allow it to fall out of scope.

Upvotes: 1

Related Questions