What I want to do is really simple and there is a syntax error that I can't understand:
I have an array that contains some objects, and I want to create another array using some value of those objects:
let fields = [{type:'a',label:'email'},{type:'b',label:'name'},{type:'a',label:'tel'}]
let respone = []
// different implementation
fields.map(item => {
respone.push({item.label: ''}) } )
`Uncaught SyntaxError: Unexpected token .`
fields.map(item => {
respone = [...response, {item.label: ''}] } )
`Uncaught SyntaxError: Unexpected token .`
fields.map(item => {
respone = [...response, {item['label']: ''}] } )
`Uncaught SyntaxError: Unexpected token [`
and obviously the error is from creating the object {item['label']: ''}.
What is the reason for those errors, and what is the best way to create new objects from the existing object values.
fields.map(({type, label}) => ({[label]: ''}))