Iterate over an object, array or string in JavaScript