for-of statement of sparse array

teramako teramako at gmail.com
Thu Jul 5 04:11:43 PDT 2012


Hi

Firefox 15 or later can use for-of statement.
I have a question about this.

    var array = new Array(3);
    for (var i in array) {
      console.log(i);
    }
    for (var v of array){
      console.log(v);
    }

This for-in code logs nothing of course but for-of code logs 3 of undefined.
And also following code is same.

    var array = [];
    array.length = 3;
    for (var i of array){
      console.log(i);
    }
    for (var v of array){
      console.log(v);
    }

Are these behaviors correct ?


More information about the es-discuss mailing list