$.Data.Stack() - Class
Data Structures are often needed in any programming model. Nedil JS supports few data structures without any size restriction.
Stack follows first in last out methodology. Stack data structure can be created in NedilJS using $.Data.Stack() class
Property
NameTypeDescription
containerArrayContainer which holds all the values in Stack
Methods
NameReturnsDescription
push ( new_element )Pushes a new element to the Top of the Stack
pop ()top elementPops out the Top element out of stack and returns the element
iterate ( handler_fn )Iterate over the Stack values and applies handler function to every value
Example 1
This example demonstrates Stack operations using $.Data.Stack class
JS HTML CSS
		$.domLoaded(function() {
		
			// create $.Data.Stack Object
			var st = new $.Data.Stack();
			
			// push few elements
			st.push(12);
			st.push(57);
			st.push(23);
			
			function showContent() {
				var cont = "";
				
				// iterate over the stack elements
				st.iterate(function(el) {
					cont += el + ", ";
				});
				
				// show stack
				$.get("#stack").text(cont);
			}
			
			showContent();			
			
			$.get("#btn1").on("click", function() {		
				var va = $.get("#inp").element().value.trim();
				
				// push new element
				st.push(va);		
				
				showContent();
			});		
			
			
			$.get("#btn2").on("click", function() {		
			
				// pop the top element
				var top = st.pop();
				
				$.get("#pop").html("Removed Element : " + top);
				showContent();
			});

		});						
						
<body>
	
	Stack
	<div id="stack"></div>
	
	<input type="text" id="inp" value="" />
	<input type="button" id="btn1" value="Push" />
	
	<input type="button" id="btn2" value="Pop" />
	<div id="pop"></div>
	
</body>
	div {
		display : inline-block;
	}
	
	#inp {
		width : 30px;
	}
	
	#stack {
		border : 1px solid #555;
		padding : 5px;
	}
Result