笔记1(对象)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="static/css/style.css">
</head>
<body>
<script type="module">
import { main } from "/Web/static/js/index.js";
main();
</script>
</body>
</html>
index.js
let person = {
name: 'DCX',
age: 25,
money: 0,
friends: ['Alice', 'Bob', 'Charlie'],
clothes: {
color: 'red',
price: 20,
},
add_money: function (x) {
this.money += x;
},
temp1: null,
temp2: undefined,
};
function main() {
console.log(person);
console.log(person.friends, person.clothes.color, person.clothes.price, person.add_money);
person.add_money(100);
console.log(person.money);
console.log(person['money']);
person['add_money'](10);
console.log(person['money']);
//c++版访问可以修改key
let key = 'name';
key = 'age';
console.log(person[key]);
//输出不存在的
console.log(person.p);
//删除
delete person.name;
console.log(person.name);
}
export {
main,
}
笔记2(数组)
index.js
//空数组
let a = [];
//空对象
let a1 = {};
let a2 = null;
let a3 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let a4 = [5, 4, 3, 1, 2];
let b = [
1,
'DCX',
['a', 'b', 3],
function () {
console.log('Hello World');
return 0;
},
{ name: 'John', age: 30 }
];
let main = function () {
console.log(b[3]());
b[0] = function () {
console.log('123');
}
b[0]();
//负数也可以
b[-10] = 1;
//未定义的就是undefined
b[10] = 0;
console.log(b.length);
b.push(1);
console.log(b[11]);
b.pop();
console.log(b[11]);
a3.splice(1, 1);
console.log(a3);
a4.sort(function (a, b) {
return b - a;
});
console.log(a4);
}
export {
main,
}