Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda