声明一个无限对象的javascript数组

时间:2017-12-03 18:48:04

标签: javascript

如何声明一个可以包含无限量值的JavaScript对象,如下所示?我是Javascript的新手。

var activities = [
  {
    subject: "",
    genre :"",
    username: "",
    aboutuser: ""
  },
  {
    subject: "",
    genre :"",
    username: "",
    aboutuser: ""
  },
  {
    subject: "",
    genre :"",
    username: "",
    aboutuser: ""
  },
  ...
]

1 个答案:

答案 0 :(得分:2)

像这样:

  let myArray = []

  myArray.push({
    subject: "",
    genre :"",
    username: "",
    aboutuser: ""
  })

只需定义一个空数组,并将对象多次推入其中。