Mangler.each() - DarthJDG/Mangler.js GitHub Wiki

Iterate through items of an object or array, calling a function for each element.

Mangler.each(iterable, callback)
Parameter Type Default Description
iterable Iterable Iterable object to loop through.
callback Function Function to call for each item. Parameters: function(key, value)

Returns

Nothing.


If you pass an array as the iterable parameter, the callback function will be called once for each element, with the array index as key, and the element as the value.

If you pass an object, callback will be called once for each object property, with the property name as key, and the property value as value.

In any case, iteration can be stopped from the callback function by returning false.

Mangler.each(['A', 'B', 'C', 'D', 'E'], function(i, item) {
	console.log(i + ': ' + item);

	if(item === 'C') return false;
});

/*
	Output:

    0: A
    1: B
    2: C
*/

Iterating through other objects

Mangler.js can be extended to be able to iterate through any kind of object, including your own. To see how to register your own object types and how it affects other Mangler.js methods, see Mangler.registerType().

By default JavaScript typed arrays are treated as single non-iterable objects. To enable iterating through native typed arrays, see the Mangler-natives module.

⚠️ **GitHub.com Fallback** ⚠️