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

207
Views
getting undefined error in JavaScript building a table

My code works if I just output it to the screen. But when I try to put the results into a table, the cell is filled in with Undefined. I think it has to do with a scoping issue but I can't seem to get it worked out. Can anyone help me understand the scoping involved here and where I am going wrong?

This is the one that doesn't work and gives the error:

var API_URL = 'https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/hunt';
$(document).ready(function() {
    $.ajax({
        type: 'GET',
        url: API_URL,

        success: function(data) {
            data.Items.forEach(function(huntItem) {
                var table = document.getElementById("hunts");
                let row = table.insertRow(1);
                let cell1 = row.insertCell(0);
                let cell2 = row.insertCell(1);
                let cell3 = row.insertCell(2);
                let cell4 = row.insertCell(3);
                let cell5 = row.insertCell(4);
                let cell6 = row.insertCell(5);
                cell1.innerHTML = huntItem.Name;
                cell2.innerHTML = huntItem.l1h;
            })

        }
    });
});

Here is the HTML:

<body>

    <h1>Hunting Results:</h1>

    <table id="hunts">
        <tr>
            <th>Player</th>
            <th>Level 1</th>
            <th>Level 2</th>
            <th>Level 3</th>
            <th>Level 4</th>
            <th>Level 5</th>
        </tr>
        <div id="playerRow">

        </div>
    </table>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It was because I had a Name with a capital N. It should be named with a lowercase n.

cell1.innerHTML = huntItem.name;
cell2.innerHTML = huntItem.l1h;

This version works now! What a rookie mistake!

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