javascript - use property value as property key using map -
this question has answer here:
i want return new array take property value become property name.
const temp = [ {name: 'james'}, {name: 'ally'} ] const new = temp.map(obj => ({ `${obj.name}`: null }))
obviously doesn't work way. clue? https://jsfiddle.net/qg8ofom1/
const temp = [ {name: 'james'}, {name: 'ally'} ]; const newobj = temp.map(obj => ({ [obj.name]: null })); console.log(newobj);
Comments
Post a Comment