简体   繁体   中英

I have to create an array with elements divided by 5 (Javscript) Sush us 5 10 15 20 ...60 (From 5 minutes to 60 minutes)

const minutes = [
  {
    value: "00",
    id: 1,
  },

  {
    id: 2,
    value: "05",
  },

  {
    id: 3,
    value: "10",
  },

  {
    id: 4,
    value: "15",
  },
  {
    id: 5,
    value: "20",
  },

  {
    id: 6,
    value: "25",
  },

  {
    id: 7,
    value: "30",
  },
  {
    id: 8,
    value: "35",
  },
  {
    id: 9,
    value: "40",
  },
  {
    id: 10,
    value: "45",
  },
  {
    id: 11,
    value: "50",
  },
  {
    id: 12,
    value: "55",
  },
];

How can i make like this dynamically

From luk2302's comment to implement,

 let arr = [] for (let i = 0; i < 12; i++) { arr.push({ id: (i + 1).toString(), value: (i * 5).toString() }) } console.log(arr)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM