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

114
Visualizações
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
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