You have 2 ways depending on if you want to convert "a" to an array or if you just want "a" to be an array.
The first method would be to run it through a function
function toArray(object) {
var array = new array();
for (key in object) {
if (object.hasOwnProperty(key)) {
array.push(object); // This is alternative for indexed array
array[key] = object; // This is for an associative array
}
}
return array;
}
Maybe have your "class" call this function and assign the return value to "a"
var item = {
'a':{'b':1000,'c':2000,'d':3000} , //how to make a variable become an array?
myfunction : function(){
this.a = toArray(this.a);
console.log(this.a[1]) // If you do indexed
console.log(this.a.b); // If you do associative
}
};
item.myfunction();
The second way was explained by @ahren which is just to define "a" as an array by [...] the values instead of {...}
You can also check out my own question put up about OOP in JavaScript, got a nice reply from T.J. about it there concerning private methods.
JavaScript OOP Pitfalls
Don't know if this is what you wanted but should work.
'b','c', or'd', then you should be able to use what you have, or even better:'a':[1000, 2000, 3000],