I'm trying to convert a number to a string to use as a key. But the problem is, when I the newly converted string, it still acts like a number. Is there a right way of doing this?
JAVASCRIPT
var arr = [];
var num = 3;
var key = String(''+num); //Convert number into string
//var key = '' +num; //Tried this
//var key = num.toString(); //Tried this also
array[key] = true;
console.log(arr); //Returns [, , true]
console.log(arr.length); //Returns 3
Basically, I want it to return just:
console.log(arr); //Return [true]
console.log(arr.length); //Return 1
[ ]operator into a string. You don't have to do anything at all.arr[3]is the same asarr["3"].3to index0?