[removed] How can I transform an array?

前端 未结 6 898
-上瘾入骨i
-上瘾入骨i 2021-01-12 05:10

I have this on a javascript var: (it\'s a http returned data, and I don\'t know if it\'s an array or string - (how can we see that?) - Update: using typeof returned \"string

6条回答
  •  有刺的猬
    2021-01-12 05:41

    Okay, firstly to get the type of a "thing", use the "typeof" operator (note that the type of an array is an object, not 'array'!):

    var a = "string";
    var b = 1;
    var c = new Array();
    alert(typeof(a)); // string
    alert(typeof(b)); // number
    alert(typeof(c)); // object
    

    To get at the values in the associative array (assuming it is one), you can just loop through it, like so:

    var d = [{"nomeDominio":"gggg.fa"},{"nomeDominio":"rarar.fa"}];
    d["bob"] = "alice";
    d["gary"] = "stephen";
    
    for(var key in d) {
        alert(d[key]);
    }
    

提交回复
热议问题