Is there a one-liner to create an array of objects of length n?
const arr = [
{ first_name: '', last_name: '' },
{ first_name: '', last_name: '' },
{ first_name: '', last_name: '' },
]
I've tried below but am getting SyntaxError: unexpected token: ':'
const arr = [...Array(3).map(x => { first_name: '', last_name: '' })]
const arr = [...Array(3).fill(1).map(...Array.from({length:3}).map(x => ({first_name: '', last_name: ''}))[...Array(n)].map(() => ({}))orArray(n).fill().map(() => ({})). I don't recommendfillthough--more typing and prone to aliasing bugs.