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

208
Visualizações
Insert a 2d array as multiple rows in a SQLite database using nodejs

This 2d array can be of any length so if for example the array is

var my_2D_Array = 
[['jack',22,'student'],
['Bob',45,'doctor'],
['bucky',30,'unelployed']]

// currently I am using this but it isn't working properly 

for(i=0;i<my_2D_Array.length;i++){
  clientChart.run(`INSERT INTO HP2255 VALUES (?, ?, ?)`,my_2D_Array[i],(err)=>{
  console.log('err' + err)
})

Is it possible to insert an array like this into the database with out using a for loop

I am really new to programming in general and if there is anything that I am missing than please help me out

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Without knowing more about your setup/table definition and based on the Usage presented in the repo I would guess something like the following:

const my_2D_Array = [
  ['jack', 22, 'student'],
  ['Bob', 45, 'doctor'],
  ['bucky', 30, 'unelployed'],
];

// explicitly declare columns (it may work without, but is more fragile and less clear)
const stmt = clientChart.prepare('INSERT INTO HP2255 (name, age, job) VALUES (?, ?, ?)');
for (const row of my_2D_Array) {
  stmt.run(...row); // spread each sub-array to pass the individual elements
}
stmt.finalize();
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