How can I check the object or variable is traversable in Javascript or jQuery?
An object or a variable which is traversable must works in for each like object.forEach()
and $.each(object, callback)
in jQuery.
Actually I want to validate it then use it in for each loops.
Update:
The solution which I looking for is something like this:
if(is_traversable($var)) {
$var.forEach(function(value, key) {
console.log(value);
}
}
And you may give me an implementation of is_traversable()
function.