determine whether it is an object

The most accurate way to determine whether an element is a js object

  1. Use the prototype method
function isObject(val) {
    return Object.prototype.toString().call(val).slice(8, -1) == "Object";
}

Because similar typeof or instanceof cannot distinguish between arrays and objects, both of which are objects, only the method of this prototype is possible

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325986750&siteId=291194637