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

129
Visualizações
Adding to an array from another file - node.js

So i am new to coding and i'm trying to add users info to my array that's in a different file.

But when i add a dummy user for testing something weird happens. If i add the dummy user with the id 00000 the id gets added as 0 when it should be 00000.

My main index.js file:

const users = require('./models/users.js');

// Test To Check Users
setInterval(() => {
  console.log(users.getuser());
}, 2000);

// Add Dummy Users For Test
setTimeout(() => {
  users.adduser({
    'username': 'user add one',
    'id': 00000
  });

  users.adduser({
    'username': 'user add two',
    'id': 565656
  });
}, 2000);

My model users.js file:

let onlineUsers = [{
  'username': 'user one',
  'id': 123
},{
  'username': 'user two',
  'id': 321
}];

const users = {
  getuser: function() {
    return onlineUsers;
  },
  adduser: function(data) {
    if (onlineUsers.some((user) => user.username != data.username)) {
      onlineUsers.push(data);
    }
  },
  removeuser: function(data) {
    if (onlineUsers.some((user) => user.username == data.username)) {
      onlineUsers = onlineUsers.filter((user) => user.username != data.username);
    }
  }
};

module.exports = users;

I hope someone can maybe tell me why the id adds / logs as 0 when it should be 00000?

Console log:

[
  { username: 'user one', id: 123 },
  { username: 'user two', id: 321 },
  { username: 'user add one', id: 0 },
  { username: 'user add two', id: 565656 }
]

Sorry if my english is not good.

about 4 years ago · Juan Pablo Isaza
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