showing results for - "javascript stack"
Claudio
30 Mar 2016
1class Stack{
2   constructor() 
3    { 
4        this.items = []; 
5    } 
6   
7    push(element) 
8   { 
9    // push element into the items 
10    this.items.push(element); 
11    }
12  
13    pop() 
14    { 
15    if (this.items.length == 0) 
16        return "Underflow"; 
17    return this.items.pop(); 
18    } 
19  
20    peek() 
21	{ 
22    	return this.items[this.items.length - 1]; 
23	} 
24  
25    printStack() 
26    { 
27    	var str = ""; 
28    	for (var i = 0; i < this.items.length; i++) 
29        	str += this.items[i] + " "; 
30    	return str; 
31    } 
32
33}
Leonardo
30 Feb 2020
1function Stack() {
2  var collection = [];
3  this.print = function() {
4    console.log(collection);
5  };
6  this.push = function(val) {
7    return collection.push(val);
8  };
9  this.pop = function() {
10    return collection.pop();
11  };
12  this.peek = function() {
13    return collection[collection.length - 1];
14  };
15  this.isEmpty = function() {
16    return collection.length === 0;
17  };
18  this.clear = function() {
19    collection.length = 0;
20  };
21}
22
queries leading to this page
stack in javascriptstack jswhere is the stack jsstack array in javascriptjavastript stackstack in jsimplement stack in javascriptcreating a stack in javascriptwhat is a stack javascriptstack array javascriptwhat is stack in javascriptwhat does stack means in javascript 3fstack functions jsarray stack javascriptstack with jsstack with plain javascriptcreating stack in js javascript stackhow to make a stack in javascriptfull javascript stackstack functions javascriptstack methods javascriptstack implementation in jsstack for jsjavascript how to implement a javascript stackcreating a stack in js stack in jsstack using array jshow to define a stack in javascriptstack meaning javascripthow to implement stack in javascriptstack in javascript w3schoolshow does the stack work javascriptuse stack in jsfunction stack javascriptstack definition in javascripjavascript stacking stacking elements in javascriptwhat is new stack in javascriptstack jsdoes javascript have stackhow to use stack in jshow to create stack in javascriptstack using javascriptis there stack in javascriptstack funtions jscreate stack in jssimple stack in javascripthow to use stack in javascriptprogram stack javascriptwhat is stack in jsstack using jsimplement stack javascripthow to implement a stack in javascriptstack methods in javascriptstacking elements jshow to implement a stack javascriptstack arrays in javascriptis there a stack in jswhat is a stack in javascriptimplement stack using javascriptimplement stack jswhat is call stack in javascript 3fstack implementation jsstack javascriptimplement a stack in jsstack methodds in javascriptmaking stack javascriptwhait is stack in javascriptcreate a stack in jsstack javascript exampleto how create stack in javscriptwhat is javascript stackstack array jsjavascript stack stackcreate stack in javascriptall javascript stackhow to make a stack in javscripthow to create a stack in jscreate a stack javascriptjs function stack examplejavascript stack functionsjs stack explainedstack explain using javascriptcreate javascript stackimplement stack in jsjavascript stack examplejavascript java stackjavscript stackjavascript stacka stack jsstack javascript arraystack code in jscreate a stack in javascripthow to create a stack in javascriptstack implementation using javascriptstack implementation in javascriptstack based javascriptstack in javascript demojs function stack stack with array javascriptcan you stack methods in javascriptjavascript array stackstack in java scripstack in array jsjs stackstack implementation javascriptwhat is stack jsstack program in javascriptstack with javascriptmake stack javascriptstack example in javascripthow to declare stack in javascriptstack method in javascriptjavascript stack implementationstack example jsjavascript stack