一、替代if.else语句
Let type=' ',
Msg=' '
If(类型='添加'){
Msg='添加'
} else {
Msg='编辑'
}
//缩写使用三元表达式
Msg=类型=='添加'?“添加编辑”2,从阵列中删除重复项
Constarr=[23,5,1,2,1,2,5,45,36]
//new Set()
Con([.new Set(arr)]) 3,if.else空语句
Let noData,
HaveData='haveData '
If (noData) {
Con(noData)
} else if (haveData) {
Con(haveData)
} else {
Con('Nothing found ')
}
//利用速记?嗯?如果表达式没有值呢?嗯?右侧用作值
Con(无数据?嗯?' Nothing found ')
Con(haveData)?嗯?' Nothing found ')交换四、两个变量
Let a=1,
b=2;
Let temp=a
A=b
B=temp
Con(a、b)
//缩写es6变量相互转换
[a,b]=[b,a]
Con(a,b) 5,转换布尔值
Con(!对了)//对了
Con(!1234)//真
Con(![])//真
Con(!String') //true
Con(!{键:' val'})//true
Con(!{})//真
Con('======================')
Con(!False) //false
Con(!0) //false
Con(!//false6,扩展运算符拼接数组
Const arr1=[1,2,3],
Arr2=[4,5,6]
Let newArr=[]
NewArr=arr1.concat(arr2)
con(newArr)/(6)[1、2、3、4、5和6]
//缩写
NewArr=[.arr1,arr2]
con(newArr)/(6)[1、2、3、4、5和6]
NewArr=[.arr1,arr2,7,8,9]
CON(NEW ARR)/(9)[1,2,3,4,5,6,7,8,9] 7,解体
Const people={
Name: 'Tom ',
Age: 23,
Gender:“男人”,
City: 'Beijing '
}
Let name=,
Age=,
Gender=,
City=
Const {name,age,gender,city}=people
Con (name,age,gender,city)//Tom 23男子北京
//缩写
Letpeopleinfo={name:age3360,gender:},
City=
CON(PEOPLEINFO)//{ NAME 3360 ' TOM ',age: 23,gender : '男人' } ' Beijing '
Const {.peopleInfo}=people
CON(PEOPLEINFO)//{ NAME 3360 ' TOM ',age: 23,gender : '男子',city: 'Beijing'}
Let isTrue=true
If(isTrue){
Con('doSomthing ')
}
//缩写
IsTrue con('doSomthing') 9,内嵌模板字符串
Const people={
Name: 'Tom ',
Age: 23,
Gender:“男人”,
City: 'Beijing '
}
//缩写
Con('他是'生,名字是'',他是'年龄,在工作')
Con(`他是$ {}生的,名字是$ {},他是$ {},他是$ {} `) 10,在数组中查找指定条件的元素项目
Const peoples=[
{name:'Tom ',age:23},
{name:'Jerry ',age:21}
]。
Let data={}
For(let I in peoples){
If(peoples[i])。name=='Jerry'){
数据=peoples [I]
}
}
Con (data)//{name3360' Jerry ',age: 21 }
//缩写
资料=((项目)=I==' Jerry ')
Con (data)//{name3360' Jerry ',age: 21 } 11,属性分配
Const name='Tom ',
Age=23,
City='Beijing '
Const people={
Name: name、
Age: age、
城市:城市
}
Con (people)//{name3360' Tom ',age: 23,city :' Beijing'}
//缩写
Const people={name,age,city}
Con (people)//{name3360' Tom ',age: 23,city :' Beijing'} 12,回收利用
Const arr=[1,2,3,4,5,6]
for(let I=0;Iarr.lengthI ){
con(arr[I]);
}
For(let I in arr){
con(arr[I]);
}
For(let item of arr){
Con(项目);
}
Arr.foreach ((item,index)={con (item,index)})
Arr.filter ((item,index)={con (item,index)})
Let newArr=[]
Newarr=arr.map ((item,index)={con (item,index));Return item})
Con(新阿尔);13、方法基本参数
Function eat(fruit){
If(!Fruit){
Con(“基本上吃香蕉”)
}else{
Con(`吃${fruit} `)
}
}
Eat()
东部(“菠萝”)
//缩写
Function eat(fruit='香蕉'){
Con(`吃${fruit} `)
}
Eat()
Eat('菠萝')14,Object.values()物件值旋转阵列
Constinfo={name:' Tom ',age:23,city3360' Beijing'}
Let arr=[]
For(let I in info){
Arr.push(info[i])
}
con(arr)/(3)[' Tom ',23,' Beijing']
//缩写
Const arr=Object.values(info)
con(arr)/(3)[' Tom ',23,' Beijing'] 15,确认阵列中存在元素
Constarr=[1,2,3,4,5,6,7,8,9,10]
Con(4)!=-1)//真
Con (4))//true16,压缩多个或条件判断
Const num=4
if(num==1 | | num==2 | | num==3 | | num==4){
Con(真)
}
If([1,2,3,4])。includes(num){
Con(真)
} 17,指数运算Ma()
Con(Ma(2,3)) //2的三次方=8
Con(Ma(4,2)) //4的2次方=16
//缩写
Con(2**3) //2的三次方=8
Con(4**2) //4的2次方=16 18,舍入
con)//12
//缩写
Con (~ ~ 12.54)//1219,分配多个变量
//19,分配多个变量
Let num1='num1 ',
Num2='num2 ',
Num3='num3 '
//缩写
Let [num1,num2,num3]=['num1 ',' num2 ',' num3']
Con(num1、num2、num 3);
//对象类型变量分配
Let people={
Name:'Tom ',
Age:23
}
Let name=
Let age=
//缩写
Let {name,age}=people
Con(name,age) //Tom 23 20,链形判断找到最后一层数据
Const people={
Name:'Tom ',
Age:23,
Address:{
City:'Beijing ',
Area:'Chaoyang '
}
}
Con(people) //undefined
Con(people) //Beijing
//缩写
Con(人物)?name) //Tom
Con(人物)?地址?province) //undefined
Con(人物)?地址?city) //Beijing注意:以上一些代码需要手动注释。否则,将报告错误!
1.《【上古卷轴5代码大全】专题js代码骚气二十招》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。
2.《【上古卷轴5代码大全】专题js代码骚气二十招》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。
3.文章转载时请保留本站内容来源地址,https://www.cxvn.com/gl/djyxgl/150034.html