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

Loads the mangler object from the top of the chain, before the first find, findOne or extract call.

.end()

Returns

Returns a reference to the previous mangler object in 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 .end() will return to the previous selection before the last call of any of the above methods. To return to the top of the chain, use .endAll().

Example

In the following example we'll increase the price of fruit, 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 })
		.end()
	.find({ type: 'vegetable' })
		.each(function(k, v) { v.price -= 1 });
⚠️ **GitHub.com Fallback** ⚠️