代码拉取完成,页面将自动刷新
<!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>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。