0

I’d like to be able to take a variable, say x, which equals 2, and append it to the name of a variable. This is probably a simple problem, or one that can’t be solved, but is there a way?

I’ve tried using

var ride+x = 3;
var ride.concat(x) = 3;
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
Gus S
  • 1
  • 2
  • 2
    No. Use [objects](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer): `const ride = { x: 3 }; console.log(ride.x);`, or, if `x` is already a variable: `const ride = { [x]: 3 }; console.log(ride[x]);`. – Sebastian Simon Dec 04 '22 at 05:10

0 Answers0