Array type in type script

后端 未结 3 439
一个人的身影
一个人的身影 2021-01-14 03:11

Why is this allowed by TypeScript? I specified a numeric index. Why can I use a string as an index? Visual studio doesn\'t report an error.

interface StringA         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-14 03:44

    An array is also an objects. So you can access the object properties.

    var array = [];
    array.push("One"); // array
    array[1]= "Two"; // array
    array['key'] = "Three";// object
    array.key2 = "Four"; // object
    var length = array.length; // Is 2 
    

提交回复
热议问题