Articles on Trending Technologies

Technical articles with clear explanations and examples

JavaScript - Convert an array to key value pair

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

Converting an array of objects to key-value pairs is a common task in JavaScript. This involves transforming structured data into a simple object where one property becomes the key and another becomes the value. Problem Statement Suppose we have an array of student objects like this: const arr = [ {"name": "Rahul", "score": 89}, {"name": "Vivek", "score": 88}, {"name": "Rakesh", "score": 75}, {"name": "Sourav", "score": 82}, {"name": "Gautam", "score": 91}, {"name": "Sunil", ...

Read More

How to set the height of an element with JavaScript?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 847 Views

Use the style.height property to dynamically set the height of HTML elements with JavaScript. This property accepts height values in pixels, percentages, or other CSS units. Syntax element.style.height = "value"; Where value can be in pixels (px), percentages (%), or other CSS units like em, rem, vh, etc. Example: Setting Button Height Heading 1 This is Demo Text. Update Height ...

Read More

How to play HTML blocks one by one with no pops and clicks?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 141 Views

To play HTML audio blocks sequentially without gaps or clicks, use the onended event to chain audio playback seamlessly. HTML Structure First, set up multiple audio elements with unique IDs: Basic Sequential Playback Use the onended event to automatically play the next audio when the current one finishes: var one = document.getElementById('one'); one.onended = function() { ...

Read More

Is their a cross-origin attribute in HTML5?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 270 Views

Yes, HTML5 includes the crossorigin attribute. According to the official specification, it's defined as: The crossorigin attribute is a CORS settings attribute. Its purpose is to allow images from third-party sites that allow cross-origin access to be used with canvas. Syntax Supported Values The crossorigin attribute accepts two values: Value Description Credentials Sent? anonymous Performs CORS request without credentials No use-credentials Performs CORS request with credentials Yes Example: Canvas Image Access ...

Read More

Remove elements from a Set using Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 273 Views

JavaScript Sets provide methods to remove elements efficiently. The primary method is delete(), which removes a specified value from the Set. Using the delete() Method The delete() method removes a value from the Set and returns true if the value existed, or false if it didn't. Syntax set.delete(value) Example: Removing Individual Elements const mySet = new Set([1, 2, 3, 4, 5]); console.log("Original Set:", mySet); // Remove elements console.log("Delete 3:", mySet.delete(3)); // true - existed console.log("Delete 10:", mySet.delete(10)); // false - didn't exist console.log("Updated Set:", mySet); console.log("Set size:", ...

Read More

How to find the minimum value of an array in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

JavaScript provides several methods to find the minimum value in an array. The most efficient approach is using Math.min() with the spread operator, though other methods like sorting are also available. Using Math.min() with Spread Operator (Recommended) The Math.min() function finds the smallest number among its arguments. Combined with the spread operator (...), it can easily find the minimum value in an array. Find Minimum function findMinimum() { var numbers = [6, 39, 55, 1, 44]; var minimum = Math.min(...numbers); ...

Read More

The yield* expression/keyword in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 189 Views

The yield* expression in JavaScript is used to delegate to another generator function or any iterable object. It yields all values from the delegated generator or iterable, effectively "flattening" nested generators. Syntax function* generatorFunction() { yield* anotherGenerator(); yield* iterableObject; } Basic Example: Delegating to Another Generator yield* Example yield* keyword in JavaScript CLICK ...

Read More

Sum of even numbers from n to m regardless if nm JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 351 Views

We are required to write a function that takes two numbers as arguments m and n, and it returns the sum of all even numbers that falls between m and n (both inclusive). For example: If m = 10 and n = -4 The output should be 10+8+6+4+2+0+(-2)+(-4) = 24 Approach We will first calculate the sum of all even numbers up to n and the sum of all even numbers up to m. Then we will check for the bigger of the two m and n. Subtract the sum of smaller ...

Read More

Returning poker pair cards - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 215 Views

We are required to write a function that takes in an array of exactly five elements representing the five cards of a poker player drawn randomly. If the five cards contain at least one pair, our function should return the card number of the highest pair (trivial if there only exists a single pair). Else our function should return false. For example: If the array is − const arr = ['A', 'Q', '3', 'A', 'Q']; Then our function should return − 'A' (as 'A' > 'Q' in card games) Card Ranking System ...

Read More

Remove array duplicates by property - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 276 Views

When working with arrays of objects in JavaScript, you often need to remove duplicate entries based on a specific property. This tutorial shows different methods to accomplish this task. The Problem Consider an array of objects with duplicate names: const arr = [ {name: "Jack", age: "14"}, {name: "bob", age: "14"}, {name: "sue", age: "21"}, {name: "Jill", age: "16"}, {name: "Jack", age: "21"} ]; console.log("Original array:"); console.log(arr); Original array: [ ...

Read More
Showing 17881–17890 of 61,297 articles
Advertisements