Web Development Articles

Page 129 of 801

How to store data to DOM?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

Storing data in the DOM means keeping data associated with HTML elements or in JavaScript variables that can be accessed later. This is useful for maintaining application state, form data, or temporary values without making server requests. In vanilla JavaScript, we can store data in objects or use element properties. jQuery provides the data() method for attaching data to specific DOM elements. Let's explore both approaches. Using JavaScript Objects to Store Data The most common approach is creating JavaScript objects to hold data. This keeps information organized and easily accessible. Syntax let dataObj = ...

Read More

How to store JavaScript functions in a queue and execute in that order?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 810 Views

In JavaScript, you may need to store functions in a queue and execute them in a specific order. Since JavaScript doesn't have a built-in queue data structure, we can use arrays with push() to enqueue functions and shift() to dequeue them. This pattern is useful for managing asynchronous operations, implementing task schedulers, or controlling execution flow in applications. Basic Queue Operations A function queue uses these core operations: Enqueue: Add function to the end using push() Dequeue: Remove and execute function from the front using shift() Execute: Call functions in First-In-First-Out (FIFO) order ...

Read More

How to switch the language of the page using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 9K+ Views

Whenever you develop a website or application for a worldwide business, you must also focus on which language your audience can understand. For example, English is an international language, but in some parts of the world, people don't understand English as they speak German, Spanish etc. However, if you have observed, then some websites provide the option to change the website's language. You just need to click on the button, which changes the whole website's language. Have you ever thought about how it is possible? Here, we will learn to switch the language of the web page using ...

Read More

How to throw an error in an async generator function in JavaScript ?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

Async generator functions combine asynchronous operations with generator functionality. When errors occur in async generators, they need special handling using throw() method or try-catch blocks with for await...of loops. What are Async Generator Functions? Async generators use async function* syntax and can yield values asynchronously. They return an async iterator that can be consumed with for await...of loops. Basic Async Generator Example let content = document.getElementById('content'); ...

Read More

How to throw an error when using a property of an object?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 715 Views

In JavaScript, objects contain properties in key-value format. When accessing non-existent properties, JavaScript returns undefined instead of throwing an error. However, you can implement custom error handling to throw errors when invalid properties are accessed. Default Behavior: Accessing Non-existent Properties By default, JavaScript returns undefined for non-existent properties: Default behavior when accessing object properties let content = document.getElementById('content'); let object = { ...

Read More

How to use a variable for a key in a JavaScript object literal?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 12K+ Views

In JavaScript, you can use variables as object keys using bracket notation or computed property names. This is useful when working with dynamic data, API responses, or when key names are determined at runtime. Using Bracket Notation (After Object Creation) The most common approach is to create the object first, then add properties using bracket notation: Using variables as key of JavaScript object let content = document.getElementById("content"); ...

Read More

How to add bootstrap toggle-switch using JavaScript?

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 1K+ Views

The Bootstrap library provides a number of features to the user to make their coding experience smooth. One of such features which the user can choose from is the toggle-switch. The toggle-switch, one of its useful features, provides users the ability to add components which can switch between two states such as on and off. Bootstrap Toggle-switch The Cascading Style Sheets (CSS) framework Bootstrap is a toolkit that makes it simpler and more standards-compliant to create websites. It can be used, alongside JavaScript, to create a responsive user interface. The simple Bootstrap toggle-switch component is used to select ...

Read More

Javascript Program for Range Queries for Frequencies of array elements

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 260 Views

We are given an array that will contain integers and another array will be given that will contain the queries and each query represents the range that we are given by the leftmost and the rightmost index in the array and an element. For that range or the subarray, we have to find the frequency of the given element present in that range. The frequency of the elements means that we have to tell for each integer present in that range how many times it occurs. For example − If, the given array is: [5, 2, 5, 3, ...

Read More

JavaScript Program for Removing Duplicates From An Unsorted Linked List

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 325 Views

The linked list is a linear data structure that consists of nodes, and each node is stored in memory in a non-contiguous manner. Nodes are connected by storing the address of the next node. We are given a linked list that will contain some integers in a random manner and not in a sorted manner. The task is to find the elements of the linked list which are repeated and we have to remove the duplicated ones. In this problem, we will keep the first copy of the elements of the linked list and remove the elements which are ...

Read More

JavaScript Program for Reversal algorithm for array rotation

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 336 Views

An array is a linear data structure used to store different types of objects. Given an array of size n and an integer k, we need to rotate the array by k elements to the left and return the rotated array. Rotation means shifting all elements to the left by k positions. Elements that move beyond the first position wrap around to the end of the array. Note − During rotation, when elements shift left, those at the beginning move to the end, creating a circular shift pattern. Let us see an example − Input: ...

Read More
Showing 1281–1290 of 8,010 articles
« Prev 1 127 128 129 130 131 801 Next »
Advertisements