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

193
Vistas
check if variable name is the same a string inside an array

I have several arrays that I json_encode form php and two variables that I get from an inputs, lets say :

let a = [1,2,3,4,5];
let b = [1,2,3,4,5];
let c = [1,2,3,4,5];
let d = [1,2,3,4,5];
let e = [1,2,3,4,5];
let f = [1,2,3,4,5];

let name = document.getElementById("some_element").value
let number = document.getElementById("some_other_element").value

I wanna check if the name is the same as the array name and then use the array with the name for example a[number].

I am not quite sure of how to do this. Any help would be really welcome.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use an object:

const arrays = {
  a: [1, 2, 3, 4, 5],
  b: [1, 2, 3, 4, 5],
  c: [1, 2, 3, 4, 5],
  d: [1, 2, 3, 4, 5],
  e: [1, 2, 3, 4, 5],
  f: [1, 2, 3, 4, 5],
};

const name = "a";
const number = 1;

console.log(arrays[name][number]);

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