EMCAScipt 6 (ES2015)
可以使用多行字符串
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<ul id="list_1">
</ul>
<script>
let name = "小三";
console.log(`她的名字叫${name}`);
document.getElementById("list_1").innerHTML = `
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
`
</script>
</body>
</html>
let arr = [99, 22, 44, ["qwe", "asd"]];
let [q, w, e, [r, t]] = arr;
console.log(q);
console.log(r);
let obj = {
a:"json",
b:123
};
let {a, b} = obj;
console.log(a)
可以将外面定义的变量直接放置在对象内
function func(){alert(888)}
let username = "柯察金";
let obj = {
username,
fun:function () {
alert(999)
},
func,
func2(){
alert(777)
}
};
console.log(obj.username);
obj.fun();
obj.func();
obj.func2();
可以指定变量接收剩余参数
function fun(x=123, y=213, z=435) {
console.log(x, y+z)
}
fun();
function fun2(x,...y) {
console.log(x, y)
}
fun2(22, 33, 44, 55, 66);
fun2(x=33, y=300, z=22)
let arr = [78, 89, 90, 101];
arr.forEach(function(value, index){
console.log(value)
});
let arr2 = arr.map(function (value, index) {
return value+1
});
console.log(arr2);
// 如果有,则返回下标,没有则返回-1
console.log(arr.indexOf(90));
console.log(arr.indexOf(900));
// 如果有,则返回true,没有则返回false
console.log(arr.includes(101));
console.log(arr.includes(100));
// 快速筛选
let arr3 = arr.filter(function (value, index) {
return value>89
});
console.log(arr3)