简体   繁体   English

polilyne对象的空属性?

[英]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 我需要清空polilyne类型的对象,以便可以根据需要多次重复使用,我希望属性为空,例如,当您拥有值时,该对象具有类似以下内容的对象

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. 我正在使用Google Maps版本3中的javascript和javascript api。setMap(null)形式不为我服务,因为它仅隐藏行,但该对象仍具有指定的values.sorry(我的英语)。

You can't just clear object values, but you can set them to null or empty array. 您不仅可以清除对象值,还可以将它们设置为null或空数组。 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) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM