Showcaselfloyd Showcaselfloyd - 1 year ago 85
Javascript Question

How do i find if an object contains an array in javascript?

I have a huge set of data which is basically an array of objects. I need to loop through all the objects to see if any contain any array themselves.

Thoughts ?

Answer Source

Try this:

for (var i = 0; i < arr.length; i++) {
    var obj = arr[i];

    for (var j in obj) {
        if (!obj.hasOwnProperty(j)) {

        if (obj[j] instanceof Array) {
            console.log(i + '.' + j + ' is array');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download