I'm encountering an issue with a JavaScript array and a variable. My goal is to add to the array an object where the property name corresponds to the variable, but it should hold the value of that variable rather than treating it as a string. Here's the code I currently have:
array = [];
var x = 10;
array.push({x: y});
Unfortunately, in this setup, "x" gets stored as a string instead of representing the actual value of var x. I would greatly appreciate any assistance on this matter.