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

139
Views
Replacing multiple variables inside an Array & then list Javascript

In the code below, I call an NBA api, and create an array from a specific bracket within it. However, this only gives me an array full of numbers, which are the NBA team's ID's. I'm trying to change all of the values into the Team name's themselves and list them. For example, '29' would be the Portland Trailblazers; 25 would be the Oklahoma City Thunder.

I've tried multiple threads with similar problems, but have yet to find something that works.

Code:

var idarray = [];

var idz = response.api.standings
for (var i = 0; i < idz.length; i++) {

    idarray.push(idz[i].teamId);
}
console.log(idarray)

Array that prints out from above code:

 [
  '41', '5',  '20', '1',  '26',
  '24', '4',  '27', '38', '2',
  '6',  '21', '7',  '15', '10',
  '19', '14', '8',  '31', '23',
  '11', '30', '28', '16', '17',
  '40', '22', '9',  '29', '25'
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

1. First of all, you need to map all team ID's to their names, something like this:

// key -> ID, value -> name
const teamNames = {
  25: 'Oklahoma City Thunder',
  29: 'Portland Trailblazers',
  ...
}

2. Then you can transform your array:

// For example idarray = [25, 29] initially
idarray = idarray.map(id => teamNames[id]);
console.log(idarray);

Output:

[ 'Oklahoma City Thunder', 'Portland Trailblazers' ]

Extra: mapped array is ready to print as standings list, for example:

for (let index in idarray) {
  console.log(`${index + 1}. ${idarray[index]}`);
}

Output:

1. Oklahoma City Thunder
2. Portland Trailblazers
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!