0

This is two object. One is 'major'. Other one is 'marjorModel'.

const major = [
  {
    id: 1,
    subject: 'math',
    title: 'no good'
  },
  {
    id: 2,
    subject: 'science',
    title: 'good'
  }
]

const majorModel = [
 {
   id: 1,
   amount: 23,
   date: '2022-03-01'
 },
 {
   id: 3,
   amount: 26,
   date: '2022-03-01'
 }
]

and I want to merge new one

example)

const newObj = [
 {
  id: 1,
  subject: 'math',
  title: 'no good',
  amount: 23,
  date: '2022-03-01'
 },
 {
  id: 2,
  subject: 'science',
  title: 'good',
  amount: 26,
  date: '2022-03-01'
 }
]

I don't know how to merge different of other object. please let me know!!

batman_jh
  • 3
  • 2

1 Answers1

0

You can use reduce

major.reduce((acc, v, i) => {
  acc.push({
    ...v,
    ...majorModel[i]
  });
  return acc;
}, []);
Brandon
  • 1,447
  • 2
  • 21
  • 41