質問

The code below will enumerate properties of an object, but can the data types be enumerated?

function enumerateAttributes(node){
    var text="";
    var attrs=circle1.getAttrs();
    for (key in attrs) {
        if (attrs.hasOwnProperty(key)) {
            text+=(key+"=="+attrs[key]+"\n");
        }
    }
    alert(text);
}
役に立ちましたか?

解決

For javascript data types you can use typeof: console.log(typeof attrs[key]);

These are some common types that will be returned:

  • null,
  • undefined,
  • object,
  • boolean,
  • number,
  • string,
  • function
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top