How to check if a JSON response element is an array?

There are other methods but, to my knowledge, this is the most reliable:

function isArray(what) {
    return Object.prototype.toString.call(what) === '[object Array]';
}

So, to apply it to your code:

for(var i in json) {                    
    if(isArray(json[i])) {
    // Iterate the array and do stuff
    } else {
    // Do another thing
    }
}

Leave a Comment

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