var i = 0; var test = 'test1_test2' ; var testr = test.split('_'); var test1 = 'tiiiies'; var test2 = 'testtyty2'; while (i < 2) { alert( window[testr[i]]) i++ }; why it does not work in the function gives undefined
var i = 0; var test = 'test1_test2' ; var testr = test.split('_'); var test1 = 'tiiiies'; var test2 = 'testtyty2'; while (i < 2) { alert( window[testr[i]]) i++ }; why it does not work in the function gives undefined
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
Because you have this code wrapped in something else ( window.onload , $(document).ready , some other function), which makes the scope of your variables not global. Try removing var before test1 and test2 .
function Test() { var i = 0; var test = 'test1_test2' ; var testr = test.split('_'); test1 = 'tiiiies'; test2 = 'testtyty2'; while (i < 2) { alert( window[testr[i]]); i++; }; } Test(); Source: https://ru.stackoverflow.com/questions/539186/
All Articles