Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
pushing data inside an existing empty array

Basically I have an main object dataToMovie, I have empty arrays. I want to display the content of the arr variable into mov[] and the content of the arr2 into ser[]. I have attempted to do something as you can see. I am looking to do this seperately for each array as I will have multiple data in the future

const dataToMovie = {
  createMovie,
  links: {
    mov: [],
    ser: [],
    rev: [],
    ext: [],
  },
};

const dataToInsert1 = {
  'model-10389': 164703,
  'model-10388': 164704,
  'model-10387': 164705,
};

const dataToInsert2 = {
  'model-10389': [1656, 1234, 1245],
  'model-10384': [1656, 1234, 1245],
  'model-10383': [1656, 1234, 1245],
};

const arr = Object.entries(dataToInsert1).map((entry) => ({
  id: entry[0].substring(6, entry[0].length),
  value: entry[1],
}));

//dataToMovie.links.mov[arr]

const arr2 = Object.entries(dataToInsert2).map(([key, value]) => ({
  modelId: key.substring(6),
  ids: value,
}));

//dataToMovie.links.ser[arr2]
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

concat is a good candidate for this operation. it returns a merged array.

dataToMovie.links.mov = dataToMovie.links.mov.concat( arr )
dataToMovie.links.ser = dataToMovie.links.set.concat( arr2 )
about 4 years ago · Juan Pablo Isaza Report

0

You are close. if the arrays are empty you can just do:

dataToMovie.links.mov = arr
dataToMovie.links.ser= arr2

If the arrays have items in them and you just want to add to them, you can use the spread operator

dataToMovie.links.mov = [...dataToMovie.links.mov, ...arr]
dataToMovie.links.ser = [...dataToMovie.links.ser, ...arr2]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!