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

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