How to list the properties of a JavaScript object?

后端 未结 17 2571
刺人心
刺人心 2020-11-22 00:34

Say I create an object thus:

var myObject =
        {\"ircEvent\": \"PRIVMSG\", \"method\": \"newURI\", \"regex\": \"^http://.*\"};

What is

17条回答
  •  终归单人心
    2020-11-22 01:10

    if you are trying to get the elements only but not the functions then this code can help you

    this.getKeys = function() {
    
        var keys = new Array();
        for(var key in this) {
    
            if( typeof this[key] !== 'function') {
    
                keys.push(key);
            }
        }
        return keys;
    }
    

    this is part of my implementation of the HashMap and I only want the keys, "this" is the hashmap object that contains the keys

提交回复
热议问题