Swapping for loop out and adding if (obj.hasOwnProperty(prop)) check to handle both objects and arrays.