Web Development Articles

Page 412 of 801

Title Case A Sentence JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 331 Views

Let's say we are required to write a function that accepts a string and capitalizes the first letter of every word in that string and changes the case of all the remaining letters to lowercase. For example, if the input string is — hello world coding is very interesting The output should be — Hello World Coding Is Very Interesting Let's define a function capitaliseTitle() that takes in a string and capitalises the first letter of each word and returns the string — Using Split and Map Method ...

Read More

How do I add a class to a given element using Javascript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 1K+ Views

In JavaScript, there are various approaches to add a class to an element. We can use the .className property or the .classList.add() method to add a class name to a specific element. The class attribute can be used in CSS to style elements and perform various tasks for elements with the same class name. Using the className Property The className property allows you to add a class to an HTML element while preserving its existing classes. This property gets or sets the value of the class attribute of an element. When adding a new class to ...

Read More

How to get the size of a json object in JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 10K+ Views

In this article, we will learn about various methods to get the size of a JSON object in JavaScript. Getting the size of a JSON object in JavaScript is the same as counting the total number of keys in an object. We can accomplish this using several different approaches. Using Object.keys() (Recommended) The Object.keys() method returns an array of the given object's enumerable property names. To get the size, we simply check the length of this array. Syntax Object.keys(objectName).length Example Size of JSON Object ...

Read More

When summing values from 2 arrays how can I cap the value in the new JavaScript array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 170 Views

When working with arrays that represent RGB color values, you often need to add corresponding elements while ensuring the result doesn't exceed the maximum value of 255. This is a common requirement in graphics programming and color manipulation. Suppose we have two arrays, each containing three elements representing the red, green, and blue color values as integers. Our goal is to add the corresponding values to form a new RGB color array, capping any value that exceeds 255. Problem Statement We need to create a function that: Takes two arrays as input (representing RGB values) Adds ...

Read More

How to do image preloading with javascript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 2K+ Views

Image preloading in JavaScript allows you to load images in advance, improving user experience by reducing loading delays when images are actually needed. This technique is especially useful for galleries, carousels, or any application where images need to appear instantly. What is Image Preloading? Image preloading downloads and caches images in the browser before they're displayed. This ensures smooth transitions and eliminates loading delays when users interact with your application. Method 1: Using Image Constructor The most common approach creates new Image objects and sets their src property: ...

Read More

How to set a countdown timer in javascript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 9K+ Views

We can set a countdown timer in JavaScript using the setInterval() method. This method continuously calls a function or executes a code snippet with a fixed time delay between every call. The setInterval() method calls a function at described intervals in milliseconds. It continues calling the function until the clearInterval() is called, or the window is closed. Syntax Following is the syntax of this method − setInterval(function, milliseconds); Parameters The setInterval method accepts two parameters: function − A function containing a block of code designed to perform ...

Read More

How to exclude certain values from randomly generated array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

We need to create a function that generates an array of random numbers while excluding certain values. The function takes two arguments: the desired array length and an array of numbers to exclude. Requirements: Generate random numbers between 0 and 100 Exclude numbers present in the exclusion array No duplicate numbers in the result Example const absentArray = [44, 65, 5, 34, 87, 42, 8, 76, 21, 33]; const len = 10; const generateRandom = (len, absentArray) => { const randomArray = []; for(let i ...

Read More

Why Ember.js is the best javascript frame work?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 300 Views

Ember.js is a powerful JavaScript framework that has maintained steady adoption among developers. According to recent surveys, approximately 6.3% of JavaScript developers currently use Ember, ranking it as the 4th most popular JavaScript framework for building complex web applications. Ember.js follows the MVVM (Model-View-View-Model) architectural pattern and is specifically designed for complex, multi-page applications. As an open-source framework, it provides a complete solution for data management and application flow, making it ideal for ambitious web projects. One of Ember's key strengths is its refined upgrade system that helps developers integrate new versions without breaking changes. This stability-focused approach ...

Read More

How to create a random number between a range JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 344 Views

Our job is to create a function, say createRandom, that takes in two arguments and returns a pseudorandom number between the range (max exclusive). Syntax const createRandom = (min, max) => { const diff = max - min; const random = Math.random(); return Math.floor((random * diff) + min); } Example const min = 3; const max = 9; const createRandom = (min, max) => { const diff = max - min; const random ...

Read More

Dynamically creating keys in JavaScript associative array

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 4K+ Views

In JavaScript, associative arrays are essentially objects that use string keys instead of numeric indices. You can dynamically add keys to these objects using square bracket notation or dot notation. When you assign values to keys in a JavaScript object, you're creating key-value pairs that can be accessed and modified dynamically. Unlike traditional arrays, these objects don't have a length property and lose array-specific methods. Creating an Associative Array Dynamically You can create a dynamic associative array by simply assigning a literal object to a variable: var arrayName = {"key1": value1, "key2": value2, "key3": value3}; ...

Read More
Showing 4111–4120 of 8,010 articles
« Prev 1 410 411 412 413 414 801 Next »
Advertisements