Array库
/** * 查找元素在数组中出现的所有位置 * @param {要查找的数组} array * @param {要查找的元素} ele * @param {回调函数} callback */ function findAllIndex(array, ele, callback) { let indices = []; if (array && Array.isArray(array) && array.length) { let idx = array.indexOf(ele); while (idx != -1) { indices.push(idx); idx = array.indexOf(ele, idx + 1); } if ((typeof callback === "function") && callback) { callback(array, indices); } return indices; } return false; }
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

更多精彩