📜  向 javascript 对象添加元素 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:55.743000             🧑  作者: Mango

代码示例1
let person = {
  name : 'John Doe',
  age : 35
}

//Now we can add element by 2 ways
person.occupation = 'Web Designer'
//or
person['occupation'] = 'Web Designer'; //This is usefull for adding element within loop.

object[yourKey] = yourValue;
object.yourKey = yourValue;