Question

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);
}
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top