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

Loads a previous mangler object from the chain, before the last find, findOne or extract call.

.endAll()

Returns

Returns a reference to the mangler object at the top of the chain.


Many mangler object methods return the mangler object itself for method chaining. Some methods however return their results wrapped in a new mangler object in order to preserve the original list of items, but also provide an easy way to chain methods.

Methods that return their result in a new mangler object:

Calling .endAll() will return to the original mangler object, before the first call of any of the above methods. To go up just one level before the last method call, use .end().

Example

In the following example we'll increase the price of fruit, change 'orange' to 'lemon', then decrease the price of vegetables.

At the end of the code, the objects are updated, but the products mangler object still contains the full product list.

products = Mangler([
	{ name: 'cherry', type: 'fruit', price: 3.00 },
	{ name: 'orange', type: 'fruit', price: 2.90 },
	{ name: 'grapes', type: 'fruit', price: 1.00 },
	{ name: 'carrot', type: 'vegetable', price: 2.00 },
	{ name: 'celery', type: 'vegetable', price: 3.50 }
]);

products
	.find({ type: 'fruit' })
		.each(function(k, v) { v.price += 1 })
		.find({ name: 'orange' })
			.each(function(k, v) { v.name = 'lemon'; })
			.endAll()
	.find({ type: 'vegetable' })
		.each(function(k, v) { v.price -= 1 });
⚠️ **GitHub.com Fallback** ⚠️