let Tarot = {
TheFool: "愚者",
TheMagician: 1,
TheHighPriestess: function () {
return 'The High Priestess';
},
TheLeangle: [1, 2, 3, 4, 5]
}
点方式
console.log(Tarot.TheFool);
中括号方式
console.log(Tarot['TheMagician']);
// 这样可以执行对象属性里面的方法
console.log(Tarot['TheHighPriestess']());
遍历对象的时候
for (const key in Tarot) {
// 这时候这里的 key 是变量,记得不要加引号,才能正常的遍历出 Tarot 对象的属性值出来
console.log(Tarot[key]);
// 这里不能用点方式执行,因为这时候用点方式执行返回的是 Tarot 的属性 key,会返回 undefined 而不会拿到对应的值。
//console.log(Tarot.key);
}
如果还有其他方法漏了,可以留言说一下互相交流。
【一切悰零开始】