Variable in for loop is a string [duplicate]

Its most likely because in this for loop style (for..in), it is treating i as a key, and since keys in objects are usually strings (yes, an array is a type of object in javascript), it is treating it as a String.

parseInt(i) works in this situation, but for good programming practice, you would want to use a for loop that looks similar to this:

var array = [1, 2, 3];
for (var i = array.length - 1; i >= 0; i--) {
    // do work with each array element here
} 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)