Search code examples
javascripttypeskineticjsenumeration

KineticJS enumerate data types of an Object


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);
}

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