• notice
  • Congratulations on the launch of the Sought Tech site

js abbreviation, can it be written in one line

Look at the notes, I hope it can be written in one sentence, is there such a simple way of writing?

const t = [
  {name: 'John', value: 111},
  {name: 'Mary', value: 222}];const param = t.reduce((p, n) => {  // Can it be written in one line here, similar to this t.map(k => k.child);
  p[n.name] = n.value;
  return p;}, {})


const t = [
  {name: 'John', value: 111},
  {name: 'Mary', value: 222}];const param = t.reduce((p, n) => (p[n.name] = n.value,p), {})

Coincidentally, I thought about this issue recently

t.reduce((p, n) => ({...p, [n.name]: n.value}), {})

const t = [
  { name: 'John', value: 111 },
  { name: 'Mary', value: 222 }];const param = t.reduce((p, n) => ({ ...p, [n.name]: n.value }), {})



Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+