随笔分类 - 数组arr
摘要:for (let idx = 40; idx >0; idx--) { if (idx % 12 0) { // break; // 终止 // return; // 终止 continue; // 跳过 } console.log(idx); }
阅读全文
摘要:/** * 数组转字符串 */ const arr = [1, 3, 5, 7, 9]; // 方法1 const str1 = arr.toString(); // str1: 1,3,5,7,9 // 方法2 const str2 = arr.join('**'); // str2: 1**3*
阅读全文
摘要:/** * 数组删除指定项 * item: 要删除的项 * array:要执行删除项的数组 * code: 数组项的唯一字段 */ arrayRemoveItem(item, array, code?: string) { const idx = array.findIndex(ite => { r
阅读全文
摘要:reduce 数组通过此方法,可以实现将每一项叠加称为一项。 使用:sum = arr.reduce(fun, start); 其中,fun为一个方法,接收四个参数,分别为 pre:初始值或者上一次叠加(计算)结果值 cur:当前项的值 index:当前项的index arr:原数组 其中,star
阅读全文