How to create an array of object literals in a loop?

后端 未结 9 1718
一整个雨季
一整个雨季 2020-12-02 03:45

I need to create an array of object literals like this:

var myColumnDefs = [
    {key:\"label\", sortable:true, resizeable:true},
    {key:\"notes\", sortabl         


        
9条回答
  •  感情败类
    2020-12-02 04:20

    If you want to go even further than @tetra with ES6 you can use the Object spread syntax and do something like this:

    let john = {
        firstName: "John",
        lastName: "Doe",
    };
    
    let people = new Array(10).fill().map((e, i) => {(...john, id: i});
    

提交回复
热议问题