随笔分类 -  数组arr

摘要:for (let idx = 40; idx >0; idx--) { if (idx % 12 0) { // break; // 终止 // return; // 终止 continue; // 跳过 } console.log(idx); } 阅读全文
posted @ 2023-07-17 13:25 冰凝^ 阅读(31) 评论(0) 推荐(0) 编辑
摘要:/** * 数组转字符串 */ 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* 阅读全文
posted @ 2021-12-24 10:56 冰凝^ 阅读(74) 评论(0) 推荐(0) 编辑
摘要:/** * 数组删除指定项 * item: 要删除的项 * array:要执行删除项的数组 * code: 数组项的唯一字段 */ arrayRemoveItem(item, array, code?: string) { const idx = array.findIndex(ite => { r 阅读全文
posted @ 2021-12-24 10:25 冰凝^ 阅读(233) 评论(0) 推荐(0) 编辑
摘要:reduce 数组通过此方法,可以实现将每一项叠加称为一项。 使用:sum = arr.reduce(fun, start); 其中,fun为一个方法,接收四个参数,分别为 pre:初始值或者上一次叠加(计算)结果值 cur:当前项的值 index:当前项的index arr:原数组 其中,star 阅读全文
posted @ 2020-03-02 11:26 冰凝^ 阅读(822) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示