1 Star 0 Fork 0

韩韶波/韩韶波20220512作业

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test1.html 5.75 KB
一键复制 编辑 原始数据 按行查看 历史
韩韶波 提交于 2022-05-12 23:36 . 韩韶波20220512作业
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var str = "笙戈瑜不喜欢风满楼";
//startsWith 以...开头
console.log(str.startsWith("笙戈瑜"));//true
//endsWith 以 ...结尾
console.log(str.endsWith("风满楼"));//true
//repeat 重复字符 后面加次数
console.log(str.repeat(6));
//padStrat 长度不够,填充到开头
let str1 = str.padStart(12,"***");
console.log(str1);
//padEnd 长度不够 填充到末尾
let str2 = str.padEnd(12,"*");
console.log(str2);
//身份证号加密1
let ididentify = "370523199711041615";
let dealid = ididentify.slice(-4);
let finalid = dealid.padStart(18,"*");
console.log(finalid);
//身份证号加密2
let ididentify1 = "370523199711041615";
let dealid1 = ididentify1.slice(-6);
let finalid1 = dealid1.padStart(18,"*");
console.log(finalid1);
//身份证号加密3
let ididentify2 = "370523199711041615";
let dealid2 = ididentify2.slice(-10);
let finalid2 = dealid2.padStart(18,"*");
console.log(finalid2);
//数组 新增方法
var arr = Array.of(1,3,5,8);
console.log(arr);
//伪数组转数组
let obj = {
0:"abc",
1:"adw",
2:"awndj",
length:3
};
console.log(obj);
//数组
let arr1 = Array.from(obj);
console.log(arr1);
//不确定
let obj2 = [
{
name:"张三",
age:18
},
{
name:"李四",
age:20
},
{
name:"王五",
age:21
}
];
console.log(obj2);
let arr2 = Array.from(obj2);
console.log(arr2);
//find方法 只返回查找到的第一个元素.
let arr_1 = [1,3,1,4,56,7,2];
//1
let resu1 = arr_1.find(function(item,idx,arr){
return item > 5;
})
//2
let resu11 = arr_1.find(function(item,idx,arr){
return item > 50;
})
//3
let resu12 = arr_1.find(function(item,idx,arr){
return item > 1;
})
console.log(resu1);
console.log(resu11);
console.log(resu12);
//findIndex 只返回查找到第一个元素的下标
let arr_2 = [1,3,1,4,56,7,2];
//1
let resu2 = arr_2.findIndex(function(item,idx,arr){
//判断条件
return item > 5;
})
//2
let resu21 = arr_2.findIndex(function(item,idx,arr){
//判断条件
return item > 1;
})
//3
let resu22 = arr_2.findIndex(function(item,idx,arr){
//判断条件
return item > 3;
})
console.log(resu2);
console.log(resu21);
console.log(resu22);
//includes 注意是includes
console.log(arr_2.includes(56));
//对象新增方法
let obj_1 = Object.assign(obj2,{"name":"李留伟","age":22});
console.log(obj_1);
//浅拷贝
let obj5 = {
name:"李四",
age:20,
hobbies:["chi","he"]
};
let obj3 = Object.assign({},obj5);
// var strs = JSON.stringify(obj3);
obj5.name = "王五";
obj5.hobbies[1] = "hes";
console.log(obj3);//未改变说明为浅拷贝
console.log(obj5);
//keys values
console.log(Object.keys(obj3));
console.log(Object.values(obj3));
//实现深拷贝
var strs = JSON.stringify(obj3);
var recept = JSON.parse(strs);
console.log(recept);
//symbol类型
let a = Symbol("name");
let b = Symbol("age");
let objs = {
[a]:"王五",
[b]:18
}
console.log(objs);
//set练习
let settest1 = new Set([1,2,4,5,6]);
console.log(settest1);
//练习测试数组去重
let arrtest1 = [1,3,2,7,1,2];
let settest2 = new Set(arrtest1);
console.log(settest2);
//数组的长度
console.log(settest2.size);
//添加数组项
settest2.add(8);
console.log(settest2);
//判断有无
console.log(settest2.has(3));
//删除
settest2.delete(3);
console.log(settest2);
//clear清空方法
settest2.clear();
console.log(settest2);
//map方法
let maptest1 = new Map([["name1","王五"],["sex1",""],["age",18]]);
console.log(maptest1);
//map类型数据的长度
console.log(maptest1.size);
//set方法
maptest1.set("hobby","乒乓球");
console.log(maptest1);
//get方法
console.log(maptest1.get("name1"));
//has
console.log(maptest1.has("name1"));
//delete
maptest1.delete("name1");
console.log(maptest1);
maptest1.clear();
console.log(maptest1);
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/adminsssa/han-shaobo-20220512-operation.git
git@gitee.com:adminsssa/han-shaobo-20220512-operation.git
adminsssa
han-shaobo-20220512-operation
韩韶波20220512作业
master

搜索帮助