Invokes the iterator function once for each item in obj collection, which can be either an
object or an array. The iterator function is invoked with iterator(value, key, obj), where value
is the value of an object property or an array element, key is the object property key or
array element index and obj is the obj itself. Specifying a context for the function is optional.
It is worth noting that .forEach does not iterate over inherited properties because it filters
using the hasOwnProperty method.
Unlike ES262's
Array.prototype.forEach,
providing 'undefined' or 'null' values for obj will not throw a TypeError, but rather just
return the value provided.
Invokes the
iterator
function once for each item inobj
collection, which can be either an object or an array. Theiterator
function is invoked withiterator(value, key, obj)
, wherevalue
is the value of an object property or an array element,key
is the object property key or array element index and obj is theobj
itself. Specifying acontext
for the function is optional.It is worth noting that
.forEach
does not iterate over inherited properties because it filters using thehasOwnProperty
method.Unlike ES262's Array.prototype.forEach, providing 'undefined' or 'null' values for
obj
will not throw a TypeError, but rather just return the value provided.