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

130
Vistas
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 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