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.
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)
//....
}