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

136
Vistas
How do I instantiate an object with a string extracted from input?

I have an input area in my HTML.

<input id="bookTitle" type="text">

Now, my javascript look like this:

function Book(title){
  this.title = title;
}

function addToLibrary(){
  const title = document.querySelector("#bookTitle").value;
  const book = new Book(title) // replace the book variable name with the value of title
}

How do I make it so that the instead of the instantiating Book Class with variable book, I instantiate it with the value of title itself.

For Example,

If my input has value "Hobbit", I want Hobbit to be the variable name instead of book.

about 4 years ago · Juan Pablo Isaza
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