Home > Software engineering >  use array methods to set changeable header for table in es6
use array methods to set changeable header for table in es6

Time:09-16

I want make a table with headers from 8 to 23 and use es6 and arrays methods I have this code to make array:

const column = Array.from(Array(16), (_, x) => [x   8]).fill({
    title: 8,
});

My current output : enter image description here

Expected output :

enter image description here

What should I do?

CodePudding user response:

Use the index provided by the callback to increment from 8 forward

const column = Array.from({ length: 16 }, (_, i) => ({ title: 8   i }));

console.log(column)

CodePudding user response:

const column = Array.from(Array(16), (_, x) => [x   8]).map(e => {
  return { title: e[0] }
});
  • Related