Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8127373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:30:23+00:00 2026-06-06T07:30:23+00:00

I have a JavaScript data structure like the following in my Node.js/Express web app:

  • 0

I have a JavaScript data structure like the following in my Node.js/Express web app:

var users = [
    { username: 'x', password: 'secret', email: 'x@x.com' }
  , { username: 'y', password: 'secret2', email: 'y@x.com' }
];

After receiving posted form values for a new user:

{ 
  req.body.username='z', 
  req.body.password='secret3', 
  req.body.email='z@x.com'
}

I’d like to add the new user to the data structure which should result in the following structure:

users = [
    { username: 'x', password: 'secret', email: 'x@x.com' }
  , { username: 'y', password: 'secret2', email: 'y@x.com' }
  , { username: 'z', password: 'secret3', email: 'z@x.com' }
];

How do I add a new record to my users array using the posted values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:30:26+00:00Added an answer on June 6, 2026 at 7:30 am

    You can use the push method to add elements to the end of an array.

    var users = [
        { username: 'x', password: 'secret', email: 'x@x.com' }
      , { username: 'y', password: 'secret2', email: 'y@x.com' }
    ];
    
    users.push( { username: 'z', password: 'secret3', email: 'z@x.com' } )
    

    You could also just set users[users.length] = the_new_element but I don’t think that looks as good.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this JavaScript code: for (var idx in data) { var row =
I have a piece of javascript code as follows: var data = { ...
I have a class structure in C#, similar to the following: [DataContract] class Data
I have a JSON-like data structure (which I don't want to change) that is
I have some javascript code that will pass data to a pop up for
I have a JavaScript based page where a grid displays all the data for
I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
Possible Duplicate: How to get JavaScript function data into a PHP variable i have
I have thought all along that I should validate form data on JavaScript when
Does anyone have any experience of storing data in JavaScript across all mobile platforms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.