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

195
Views
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 answers
Answer question

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