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

137
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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