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

110
Views
Making permanent changes to 2D Array in Javascript
var userJohn = new Member ('John', '20');
var userKelly = new Member ('Kelly', '24');
class Member {
    constructor (name, age) {
        this.name = name;
        this.age = age;
    }
}
function subMemberGroups() {
    for (var i = 0; i < memberGroup.length; i++) {
        subMemberGroup.push(memberGroup[i]["name"]);
    }
}
while (true) {
        var memberName = input.question("Please enter member's name: ");
        memberName = memberName.substring(0, 1).toUpperCase() + memberName.substring(1).toLowerCase();
        subMemberGroups();
        if (subMemberGroup.includes(memberName)) {
            console.log ("\nMember's name exists in database. Please enter a new name.");
        }
        else if (memberName.search(/^[a-zA-Z\s]+$/) == -1) {
            console.log ("Invalid Name!");
        }
        else if (memberName.search(/^[a-zA-Z\s]+$/) == 0) {
            var memberAge = input.question("Please Age: ");
            var userNew = new Member (memberName, memberAge);
            memberGroup.push(userNew);
            break;
        }
    }

What the above codes are doing is asking user to input a name. The function subMemberGroups will then check if the name that the user has input exists in the array. If John is input by the user, then it will be invalid after the function has check. After which, if all else is good i.e the name doesn't exist and if the name as no number or special characters, it will then be pushed to a new array called userNew.

What I am trying to achieve here is to permanently add the new user to the array without the data being lost after exiting the program. I am currently using Visual Studio Code and whenever I ctrl C to exit, all the existing data is lost i.e the new user I added. Is there any solution to this?

about 4 years ago · Santiago Gelvez
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!