- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 8894 Articles for Front End Technology
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
211 Views
Consider a simple stack class in Javascript.Exampleclass Stack { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; // Init an array that'll contain the stack values. this.container = []; } // A method just to see the contents while we develop this class display() { console.log(this.container); } // Checking if the array is empty isEmpty() { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
191 Views
Consider the following stack class in Javascript with few small helper functions.Exampleclass Stack { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; // Init an array that'll contain the stack values. this.container = []; } // A method just to see the contents while we develop this class display() { console.log(this.container); } // Checking if the array is ... Read More
![Sai Teja Kotha](https://www.tutorialspoint.com/assets/profiles/531230/profile/60_2591309-1671185889.png)
2K+ Views
In this article, we are going to discuss how to create the stack data structure in JavaScript. It is a linear data structure where the push and popping of elements follow the LIFO (last in first out and FILO (first in last out) sequence. Though Arrays in JavaScript provide all the functionality of a Stack, let us implement our own Stack class. Our class will have the following functions. push(element) − Function to push elements on top of the stack. pop() − Function that removes an element from the top and returns it. peek() − Returns the element on ... Read More
![Sai Teja Kotha](https://www.tutorialspoint.com/assets/profiles/531230/profile/60_2591309-1671185889.png)
686 Views
In this article, we are going to discuss the stack data structure in JavaScript. A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc. A stack allows operations at one end only. This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element which is placed (inserted or added) last, is accessed first. In stack terminology, insertion operation is called PUSH operation and removal operation is called POP ... Read More
![Sai Teja Kotha](https://www.tutorialspoint.com/assets/profiles/531230/profile/60_2591309-1671185889.png)
233 Views
In this article, we are going to discuss the importance of iterator functions in JavaScript. We can use the iterator function to iterate over an array. Other than Explicit iteration, Javascript provides a variety of iteration functions that you can use to iterate over arrays. Here, we use the forEach(), the filter method(), and the map() method to iterate over the arrays and perform the required operations. ForEach Function This function takes a function as a parameter and executes it as you pass to it for every object in the array.Syntax Following is the syntax of the forEach() method. array.forEach(function(currentValue, ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
184 Views
The do...while loop is similar to the while loop except that the condition check happens at the end of the loop. This means that the loop will always be executed at least once, even if the condition is false.For example,Examplelet i = 0; do { console.log("Hello"); i = i + 1; } while (i < 5);This will give the output −OutputHello Hello Hello Hello Hello
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
231 Views
Basically, multi-dimension arrays are used if you want to put arrays inside an array. Let's take an example. Say you wanted to store every 6 hour's temperature for every weekday. You could do something like −let monday = [35, 28, 29, 31]; let tuesday = [33, 24, 25, 29]; //...This is a good place to use a multidimensional array instead. A multidimensional array is nothing but an array of arrays. If we take forward our example, each row will represent a day while each entry in the row will represent a temp entry. For example, let temps = [ ... Read More
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
382 Views
Javascript provides a collection of functions that you can use to find elements in an array. Let's start with the most basic one. The indexOf function goes through the entire array and returns the index of the element you searched for, if it is found else it returns -1. For example, Examplelet people = ["Harry", "Martha", "John", "Sam"]; console.log(people.indexOf("John")) console.log(people.indexOf("Jim"))OutputThis will give the output −2 -1There are other, more complex functions that you can use to make search more powerful. Let's look at find() method. The find() method returns the first object matching the condition you provide it as the ... Read More
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
167 Views
There are two ways to join 2 arrays in Javascript. If you want to get a new array and not want to disturb the existing arrays while joining the two arrays then you should use the concat method as follows − Examplelet arr1 = [1, 2, 3, 4]; let arr2 = [5, 6, 7, 8]; let arr3 = arr1.concat(arr2); console.log(arr1); console.log(arr2); console.log(arr3);OutputThis will give the output −[1, 2, 3, 4] [5, 6, 7, 8] [1, 2, 3, 4, 5, 6, 7, 8]Note that the existing arrays were not modified. If you want to join in place, you'll need to use the ... Read More
![Sai Teja Kotha](https://www.tutorialspoint.com/assets/profiles/531230/profile/60_2591309-1671185889.png)
189 Views
In this article, we are going to discuss removing an element from a given position of the array in JavaScript. The delete operator, the slice() method, and the splice() method can be used to remove an element from a given position of the array in this article. Following is the syntax of the delete operator. let del = delete arr[index]; Following is the syntax of the slice() method. arr.slice(start, end) Following is the syntax of the splice() method. arr.splice(position, no_of_elem) Using delete Operator Example In this example, we are going to discuss the use of the ... Read More