html table based upon json object tree

This question already has an answer here:

  • Check if object is array? 38 answers

  • Checking typeof key === 'array' is incorrect since for arrays typeof will return "object" . You can try to use instanceof instead:

    if (key instanceof Array) {
        // do something
    } else {
        // do another stuff
    }
    

    But this will fail if your JSON was created in another frame. Another option is to check toString()

    Object.prototype.toString.call(key).indexOf('Array') > 0
    

    or to check

    Array.isArray(key)
    

    but it does not supported by all browsers.

    Description of typeof you can see here https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/typeof

    链接地址: http://www.djcxy.com/p/27568.html

    上一篇: 如何将数组或字符串转换为JavaScript中的数组?

    下一篇: 基于json对象树的html表