Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!