Declaring array of objects

前端 未结 15 1454
遇见更好的自我
遇见更好的自我 2020-12-02 07:01

I have a variable which is an array and I want every element of the array to act as an object by default. To achieve this, I can do something like this in my code.



        
15条回答
  •  执念已碎
    2020-12-02 07:37

    Use array.push() to add an item to the end of the array.

    var sample = new Array();
    sample.push(new Object());
    

    you can use it

    var x = 100;
    var sample = [];
    for(let i=0; i

提交回复
热议问题