JSFiddle - React, Tailwind, and code Playground
JavaScript
var x = {
a: 1,
b: 2,
c: 3,
d: 4,
e: "bar"
};
var y = [1, 2, 3, 4, "foo"];
function forIn(obj) {
var isArray = Array.isArray(obj),
temp = isArray ? obj : Object.keys(obj);
temp.forEach(function (value, index, array) {
console.log(this[isArray ? index : value]);
}, obj);
}
forIn(x);
forIn(y);