Kelebra93
Kelebra93

Reputation: 39

Empty properties of a polilyne object?

I need to empty a polilyne type object so it can be reused as often as needed, I want the properties to be empty, for example the object when you have values has something like this

var line = {
  route: [coor1, coor2, coor3],
  origin: cdmx,
  destination: colima
}

What I want is to empty that object and to remain like this:

var line = {
  path: [],
  origin
  destination
}

I am using javascript and the javascript api from google maps version 3. The form setMap (null), does not serve me since it only hides the line but the object is still there with its assigned values.sorry for my english.

Upvotes: 0

Views: 37

Answers (1)

P.S.
P.S.

Reputation: 16384

You can't just clear object values, but you can set them to null or empty array. Here is the snippet:

var line = {
  route: ['coor1', 'coor2', 'coor3'],
  origin: 'cdmx',
  destination: 'colima'
}

for (var property in line) {
    if(Array.isArray(line[property])) line[property] = [];
    if(typeof line[property] === 'string' || typeof line[property] === 'number') line[property] = null;
}

console.log(line)

Upvotes: 2

Related Questions