简体   繁体   中英

How to dynamically create associative array

I am currently doing this but it isn't working:

var tempArray=new Array();
var number = 15;
tempArray[number]='blabla';

           for (var key in tempArray) {
                        alert(tempArray[key]);
                    }

the output that I get is:

in_array function (element) { var retur = false; for (var values in this) { if (this[values] == element) { retur = true; break; } } return retur; }

What am I doing wrong?

In JavaScript we use Objects.

var obj = {};

obj["15"] = "blabla";
obj.fifteen = "blablah";

for(var i in obj) {
    alert(obj[i]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM