Equivalent of Python's dir in Javascript

后端 未结 6 1573
孤城傲影
孤城傲影 2020-12-03 04:06

when I write Python code from the interpreter I can type dir() to have a list of names defined in the current scope. How can achieve to have the same informatio

6条回答
  •  情深已故
    2020-12-03 04:44

    This may work for you, if you need a simple solution:

    function dir(object) {
        stuff = [];
        for (s in object) {
            stuff.push(s);
        }
        stuff.sort();
        return stuff;
    }
    

提交回复
热议问题