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

117
Vistas
Getting JS object values from html input

So basically my issue is that I'm looking to get some data from an object. The object is picked from and html tag and the selected option is put into a function. The function handles getting the data but throws an error when trying to get the length of an array found inside the object. getRandInRange is a function I created that works perfectly so that is not the issue.

When I run the code in the browser this is the error I get

Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at buildHorde (app.js:46:60)
    at setValue (app.js:33:5)
    at HTMLInputElement.onclick (index.html:27:101)
function buildHorde(obj,num){
    // for every num add a random coin roll
    for (i = 0; i < num; i ++){
        coinArr.push(obj.coins[getRandInRange(0, obj.coins.length-1)]);
    }
    // following lines add the new arrays into the html document.
    document.getElementById("coins").innerHTML = coinArr;
    return;
}
<p>Select Party Level: <select name="Party Level" id="getObj">
    <option value=level1>level1</option>
    <option value=level2>level2</option>
</select></p>

And this is the code to set the arguments in the function

function setValue(){
    var select = document.getElementById('getObj');
    obj = select.options[select.selectedIndex].value
    num = document.getElementById('getNum').value;
    buildHorde(obj,num);
}

level1 object

let level1 = {
    coins: ["No coin", getRandInRange(1,6) * 1000 + " Copper Pieces ", getRandInRange(1,8) * 100 + " Silver Pieces ", getRandInRange(1,4) * 10 + " Platinum Pieces "],
    goods: ["nothing ", "Extravagant painting ", "ornate statue "],
    items: ["Boots of speed ", mundane.weapon[getRandInRange(0, mundane.weapon.length-1)], "Potion of fire breathing "],
}
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