首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    20个 Javascript 技巧,提高我们的摸鱼时间!

    在我们的日常任务中,我们需要编写函数,如排序、搜索、寻找惟一值、传递参数、交换值等,所以在这里分享一下我工作多年珍藏的几个常用技巧和方法,以让大家增加摸鱼的时间。...a:b); // 输出: 2 3.排序字符串,数字或对象等数组 我们有内置的方法sort()和reverse()来排序字符串,但是如果是数字或对象数组呢 字符串数组排序 const stringArr...| 1; } // 输出 {k: 2, a: 3, p: 2, i: 2, l: 2} 或者 const countMap = new Map(); for (let i = 0; i string.length...; i++) { if (countMap.has(string[i])) { countMap.set(string[i], countMap.get(string[i]) + 1...使用解构来交换两个数 let a = 5; let b = 8; [a,b] = [b,a] [a,b] // 输出 (2) [8, 5] 19.

    24120

    20个 Javascript 技巧,提高我们的摸鱼时间!

    在我们的日常任务中,我们需要编写函数,如排序、搜索、寻找惟一值、传递参数、交换值等,所以在这里分享一下我工作多年珍藏的几个常用技巧和方法,以让大家增加摸鱼的时间。...a:b); // 输出: 2 3.排序字符串,数字或对象等数组 我们有内置的方法sort()和reverse()来排序字符串,但是如果是数字或对象数组呢 字符串数组排序 const stringArr...| 1; } // 输出 {k: 2, a: 3, p: 2, i: 2, l: 2} 或者 const countMap = new Map(); for (let i = 0; i string.length...; i++) { if (countMap.has(string[i])) { countMap.set(string[i], countMap.get(string[i]) + 1...使用解构来交换两个数 let a = 5; let b = 8; [a,b] = [b,a] [a,b] // 输出 (2) [8, 5] 19.

    20530
    领券