一些在前端项目中会用到的快捷操作,下面的代码都可以直接复制到控制台运行。
创新互联自2013年创立以来,是专业互联网技术服务公司,拥有项目成都网站制作、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元德江做网站,已为上家服务,为德江各地企业和个人服务,联系电话:13518219792
- let floatNum = 100.5;
- let intNum = ~~floatNum;
- console.log(intNum); // 100
- let str="10000";
- let num = +str;
- console.log(num); // 10000
Falsy为Javascript中所有可以转换为false的值的统称,共8个:false本身、空字符串、null、undefined、NaN、数字0、数字-0、大数字0n。
除Falsy值外其他所有值都是Truthy
- let falseNum = 0;
- let falseStr = "";
- let falseUndefined;
- let falseNull = null;
- let falseNaN = 0/0;
- let trueNum = 1;
- let trueStr = "何方";
- let trueObj = {name:"何方"};
- let trueArr = ["前端","后端"];
- console.log("falseNum", !!falseNum); // false
- console.log("falseStr", !!falseStr); // false
- console.log("falseUndefined", !!falseUndefined); // false
- console.log("falseNaN",!!falseNaN); // false
- console.log("trueNum",!!trueNum); // true
- console.log("trueStr",!!trueStr); // true
- console.log("trueObj",!!trueObj); // true
- console.log("trueArr",!!trueArr); // true
- let obj = {
- key1: "value1",
- key2: "value2"
- };
- let revert = {};
- Object.entries(obj).forEach(([key, value]) => revert[value] = key);
- console.log(revert);
值类型数组
- let arrNum = [
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
- ];
- let arrString = [
- "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
- "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"
- ];
- let arrMixed = [
- 1, "1", "2", true, false, false, 1, 2, "2"
- ];
- arrNum = Array.from(new Set(arrNum));
- arrString = [...new Set(arrString)];
- arrMixed = [...new Set(arrMixed)];
- console.log(arrNum); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
- console.log(arrString); // ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
- console.log(arrMixed); // [1, "1", "2", true, false, 2]
引用类型数组
- let arrObj = [
- {name: "何方"},
- {name: "王二"},
- {name: "何方"},
- {name: "何方"},
- {name: "何方"},
- {name: "何方"},
- {name: "王二"},
- {name: "王二"},
- {name: "王二"},
- {name: "王二"},
- ];
- let arrObj2 = [];
- arrObj.forEach(item => {
- arrObj2.find(find => find.name === item.name) || arrObj2.push(item)
- });
- console.log(arrObj2);
本文题目:5个能提高前端工作效率的操作
当前链接:http://www.shufengxianlan.com/qtweb/news49/158849.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联