Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Stack Example In JavaScript

class Stack {
  constructor() {
    this.items = [];
  }

  push(item) {
    this.items.unshift(item);
  }

  pop() {
    return this.items.shift();
  }

  peek() {
    return this.items[0];
  }

  isEmpty() {
    return this.items.length === 0;
  }
}


let s =	new Stack();
s.push("one");
s.push("two");
s.push("three");
s.pop("two");
console.log(s);
 
PREVIOUS NEXT
Tagged: #Stack #Example #In #JavaScript
ADD COMMENT
Topic
Name
4+9 =