JS版in_array()与is_array()

功能仿照PHP中的in_array()和is_array()

代码如下

    /**通用方法: js版in_array */
    function in_array(search, array) {
        for (var i in array) {
            if (array[i] == search) {
                return true;
            }
        }
        return false;
    }

    /**通用方法: 判断是否是数组 */
    function is_array(o) {
        return Object.prototype.toString.call(o) == '[object Array]';
    }

Posted: 十二月 2nd, 2019


Subscribe for email updates

发表评论

Note: Wrap all of your code blocks in <code>...</code> and replace < and > with &lt; and &gt;, respectively.