Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Sai Teja Kotha
9 articles
Removing an element from the start of the array in javascript
In JavaScript, there are several methods to remove the first element from an array. The most common approaches are using the shift() method, slice() method, or the Underscore.js _.rest() method. Using shift() Method (Recommended) The shift() method removes and returns the first element from an array, modifying the original array. Syntax array.shift() Example Remove first element using shift() ...
Read MoreRemoving an element from a given position of the array in Javascript
In JavaScript, you can remove an element from a specific position in an array using several methods. Each approach has different behaviors and use cases. Syntax Here are the main syntaxes for removing elements: // Delete operator (leaves undefined) delete arr[index]; // Slice method (creates new array) arr.slice(0, index).concat(arr.slice(index + 1)); // Splice method (modifies original array) arr.splice(index, 1); Using delete Operator The delete operator removes an element but leaves undefined in its place, keeping the array length unchanged. Remove element using delete ...
Read MoreStack Data Structure in Javascript
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. Element 1 (Top) Element 2 Element 3 Element 4 (Bottom) LIFO ...
Read MoreQueue Data Structure in Javascript
In this article, we are going to discuss the queue data structure in JavaScript. It is a linear data structure where the enqueue and dequeue of elements follow the FIFO (first in first out) principle. The queue is open at both ends - one end is used to insert data (enqueue) and the other is used to remove data (dequeue). We use two pointers: rear for insertion and front for removal. A real-world example of the queue can be a single-lane one-way road, where the vehicle that enters first, exits first. Other examples include printer job queues, task scheduling, ...
Read MoreThe Priority Queue in Javascript
In this article, we are going to discuss the priority queue data structure in JavaScript. A priority queue is an abstract data type (ADT) which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue. How Priority Queue Works Priority queues maintain elements in sorted order based on their priority values. Lower priority ...
Read MoreTypes of Linked List in Javascript
A linked list is a dynamic data structure where elements (nodes) are connected through pointers rather than stored in contiguous memory locations. Unlike arrays, linked lists allow efficient insertion and deletion without memory waste, as memory is allocated as needed. JavaScript supports three main types of linked lists: Singly Linked List − Navigation is forward-only through next pointers Doubly Linked List − Bidirectional navigation with both next and previous pointers Circular Linked List − The last node connects back to the first node, forming a loop ...
Read MoreDoubly linked lists in Javascript
In this article, we are going to discuss a Doubly Linked List Class data structure in JavaScript. This is a linear data structure. Doubly linked lists are almost the same as a singly linked list in all operations, we just need to keep track of one extra link per node. In singly linked lists, we just had next links, in doubly linked lists, we have 2 links, next and prev. Structure of Doubly Linked List Doubly linked lists are represented as: ...
Read MoreHow to get the Width and Height of the screen in JavaScript?
In this article, we are going to discuss how to get the width and height of the screen in JavaScript. JavaScript provides a window.screen object that contains information regarding the user's screen. The information includes height and width, and also many other features like color depth and pixel density. To find the height and width of the screen you need to use the following read-only properties: screen.height − This property returns the height of the screen in pixels. screen.width − This property returns the width of the screen in pixels. ...
Read MoreHow to modify an array value of a JSON object in JavaScript?
In JavaScript, JSON objects are regular JavaScript objects that can contain arrays. Modifying array values within these objects is straightforward using array indexing or array methods. When working with JSON objects containing arrays, you can access and modify array elements just like you would with any JavaScript array, using bracket notation or array methods. Syntax To modify an array value in a JSON object: // Direct index assignment jsonObject.arrayProperty[index] = newValue; // Using array methods jsonObject.arrayProperty.push(newValue); jsonObject.arrayProperty.splice(index, 1, newValue); Method 1: Direct Index Assignment The simplest way to modify an array ...
Read More