// 创建一个简单的 JavaScript 对象
const person = {
  firstName: "John",
  lastName: "Doe",
  age: 30,
  hobbies: ["reading", "swimming", "coding"],
  greet: function() {
    console.log(`Hello, my name is ${this.firstName} ${this.lastName}.`);
  }
};
// 访问对象的属性
console.log(person.firstName); // 输出: John
console.log(person.hobbies[1]); // 输出: swimming
// 调用对象的方法
person.greet(); // 输出: Hello, my name is John Doe.person 的对象,包含多个属性(如 firstName, lastName, age 等)和一个方法 greet。.)访问对象的属性,例如 person.firstName。person.greet()。上一篇:js new set
下一篇:js 获取get参数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站