Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda