Why object property assignment in not restricted within (for in) loop? any use case?
for in loop assigns object properties to the left side variable.

Shouldn't it be used only for 'inside the body of loop'. I don't know permanent assignment(obviously before completion of script) makes any sense?

Does anyone see use case?

Below script copies object properties to the array.


    var obj = {a:1,b:2};
    var arr = [];
    var x = 0;

    for(arr[x++] in obj) // shouldn't be temporary assignment?
    {}

    for(new_values in arr){    
    console.log(arr[new_values])  // i can fetch values here.
    }

    //a
    //b
Why object property assignment in not restricted within (for in) loop? any use case?
===

for in loop assigns object properties to the left side variable.

Shouldn't it be used only for 'inside the body of loop'. I don't know permanent assignment(obviously before completion of script) makes any sense?

Does anyone see use case?

Below script copies object properties to the array.


    var obj = {a:1,b:2};
    var arr = [];
    var x = 0;

    for(arr[x++] in obj) // shouldn't be temporary assignment?
    {}

    for(new_values in arr){    
    console.log(arr[new_values])  // i can fetch values here.
    }

    //a
    //b