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

164
Views
How to export and import an array with dynamic values in it, in javascript?

I have an array that take dynamically objects as values. I want to export it (with all values, of course) to another js file and have access to all the elements (actually objects) of the array from there but, can't find how... Any ideas will be very appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do this in 2 ways 1) Persist the data into a file as json. When you have all your data collected write it to a .json file. Then you can read it in another file and access the data. (Note: only in Node.js environment)

// file1.js
const fs = require('fs')
const data = [your_ready_data]
const stringified = JSON.stringify(data)
fs.writeFileSync("store.json", stringified, {encoding: "utf8"});

// file2.json
const dataString = fs.readFileSync("store.json", { encoding: "utf8" });
const data = JSON.parse(dataString) // 
// ...

2) send as argument.

//file1.js
const mainFunction = (list) => {
  //....
}


// file2.js
import mainFunction from 'file1.js'
const collectDate = () => {
  //....
  const data = [your_ready_data]
  
  mainFunction(your_ready_data)
  //....
}
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!