Now I have object like this
let arr = [{name:'first'},{name:'first1'}] Exprected
[{value:'first'},{value:'first1'}] My attempt
let result = arr.map(el=>{ const {name, ...other} = el; return {value: el.name, ...other} }) Now I have object like this
let arr = [{name:'first'},{name:'first1'}] Exprected
[{value:'first'},{value:'first1'}] My attempt
let result = arr.map(el=>{ const {name, ...other} = el; return {value: el.name, ...other} }) you can do it that way!
let arr = [{name:'first'},{name:'first1'}] //{value: 'first'} let result = arr.reduce((acc,el)=>{ return [...acc, {'value' : el.name}] },[]) reduce instead of map when the input and the output have the same number of elements?