-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
105 lines (82 loc) · 2.42 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// const str = "hello";
// switch (typeof str) {
// case "number" | "string":
// console.log("可以组合!");
// break;
// default:
// console.log("不可以组合,错误的写法");
// }
// const obj = { 1: 1, 2: 2, 3: 2, 4: 4 };
// for (const key in obj) {
// console.log(key, obj[key]);
// }
// console.log([1, 2, 3, 4].slice(1));
// let hello = true;
// const RESOLVED = Promise.resolve();
// RESOLVED.then().finally(() => {
// console.log("----");
// hello = false;
// });
// RESOLVED.then(() => {
// console.log("++++", hello);
// hello = "Hello";
// });
// Promise.resolve()
// .then(() => {
// console.log(hello);
// })
// .finally(() => {
// console.log(hello);
// });
// let ans = 0
// let s = "6463375576651656565"
// s = "26376256545637532656"
// for (const d of s) {
// ans += parseInt(d)
// console.log(d);
// }
// console.log(ans / 20)
// slice 将截取的返回
const s = " woshi ";
console.log(s.match(/^([\t\r\n\f ])+/));
// console.log(s.substring(0, s.indexOf("w")))
console.log(s.slice(0, s.indexOf("w")));
console.log(s.slice(s.indexOf("w")));
const div = "<div> Hello </div>";
const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(div);
console.log(match);
/* () 和 , 表示运算符,特别是,逗号运算符,会返回后一个表达式 */
console.log((1, 2));
console.log((1, 2, 3, 4));
/* 对于中括号[]来说,也会有比较奇怪的时候,但是请记住:js的数组是对象!对象可以用[]取值
第一个中括号表示数组对象,第二个中括号表示用key取值,[1][0]==1, [1][1]==undefined */
// [1,2,3,4]对象,[1,2]==[(1,2)]=[2],所以[1,2,3,4][1,2]=[1,2,3,4][2]=3
console.log([1, 2, 3, 4][(1, 2)]);
console.log([].map((child) => "<>").join(","), "===");
console.log(/(\+\+|--|\+=|-=|\*=|\/=)?[\t ]*?$/.test("() i++ \n\n"));
// console.log({} instanceof HTMLElement)
// console.log("(item, index) in items".split(/\sin\s|\sof\s/))
console.log("123".split(""));
console.log([...new Array(10).keys()]);
console.log(Array.from({ length: 10 }, (_, i) => i + 1));
console.log(Object.entries({ wode: "世界", H: "Hosh " }));
obj = {
name: "lisi",
age: 18,
height: 1.9,
if: "hello",
};
const { age } = obj;
console.log(age);
console.log(obj);
let arr = [1, 2, 3, 4, 5, 6, 7];
let sarr = arr.map((v, i) => {
console.log(v, i);
if (i == 3) {
arr.push(5);
}
return v;
});
console.log(sarr);
arr = [1];
console.log(arr.values())