Articles on Trending Technologies

Technical articles with clear explanations and examples

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

Explain 'dotAll' flag for regular expressions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 318 Views

The dotAll flag returns true or false depending upon if the s flag has been set in the regular expression. The s flag enables "dotAll" mode, where the dot . metacharacter matches any character, including newlines. What is the dotAll Flag? By default, the dot . in regular expressions matches any character except newlines. When the s flag is used, the dot can also match newline characters (, \r, etc.), making it truly match "any" character. Syntax regex.dotAll // Returns true if 's' flag is set, false otherwise Example: Checking dotAll Flag ...

Read More

Reorder array based on condition in JavaScript?

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

Let's say we have an array of objects that contains the scores of some players in a card game: const scorecard = [{ name: "Zahir", score: 23 }, { name: "Kabir", score: 13 }, { name: "Kunal", score: 29 }, { name: "Arnav", score: 42 }, { name: "Harman", score: 19 }, { name: ...

Read More

JavaScript Sum function on the click of a button

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

In JavaScript, you can create a sum function that executes when a button is clicked. This involves defining a function and attaching it to the button's onclick event. Basic Button Setup Here's how to create a button that calls a function with a parameter: Sum When clicked, this button calls the addTheValue() function with the value 10 as a parameter. Complete Example Sum Function Example Adding 10 each ...

Read More

How to ignore using variable name as a literal while using push() in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 310 Views

To avoid using a variable name as a literal string when pushing objects to an array, use square brackets [variableName] for computed property names. This allows the variable's value to become the property key. The Problem with Literal Property Names When you use name: value in an object, "name" becomes a literal string property, not the variable's value: var name = "David"; var data = []; // This creates a property literally named "name" data.push({ name: "This will always be 'name' property" }); console.log(data); [ { name: 'This will always be 'name' ...

Read More

Reverse only the odd length words - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 601 Views

We are required to write a JavaScript function that takes in a string and reverses the words in the string that have an odd number of characters in them. Any substring in the string qualifies to be a word, if either it is encapsulated by two spaces on either ends or present at the end or beginning and followed or preceded by a space. Let's say the following is our string: const str = 'hello beautiful people'; The odd length words are: hello (5 characters - odd) beautiful (9 characters - odd) ...

Read More

How to use JavaScript to replace the content of a document with JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 3K+ Views

In this tutorial, we will learn how to use JavaScript to replace the entire content of an HTML document. JavaScript provides three document methods that work together to achieve this: open(), write(), and close(). The Three Methods document.open() − Opens a new document stream for writing. It takes two optional parameters: the MIME type (typically "text/html") and "replace" to replace the current document's history entry. document.write() − Writes content to the document stream. ...

Read More

Is their JavaScript "not in" operator for checking object properties?

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 2K+ Views

JavaScript doesn't have a built-in "not in" operator, but you can achieve the same functionality by negating the in operator with ! or using other methods to check if a property doesn't exist in an object. Using Negated "in" Operator The most straightforward approach is to negate the in operator using the logical NOT operator (!): let obj = {name: "John", age: 30}; // Check if property does NOT exist if (!("email" in obj)) { console.log("Email property does not exist"); } else { console.log("Email property exists"); } ...

Read More

Cross domain HTML5 iframe issue

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 579 Views

Cross-domain iframe communication is restricted by the Same-Origin Policy for security. The postMessage method provides a safe way to transfer data between different domains in HTML5. The Cross-Domain Problem When an iframe loads content from a different domain, direct JavaScript access is blocked: // This will throw a security error let iframeContent = document.getElementById('myIframe').contentDocument; // Error: Blocked by CORS policy Solution: Using postMessage The postMessage API allows secure communication between different origins. Syntax targetWindow.postMessage(message, targetOrigin); Parameters message - Data to send (string, object, etc.) targetOrigin - ...

Read More

Usage of border-left-color property in CSS

George John
George John
Updated on 15-Mar-2026 83 Views

The border-left-color property in CSS is used to set the color of an element's left border. This property only works when a left border is already defined using the border-left-style or border property. Syntax border-left-color: color | transparent | initial | inherit; Parameters Value Description color Sets the left border color (hex, rgb, color name) transparent Makes the left border transparent initial Sets to default value inherit Inherits from parent element Example ...

Read More
Showing 17211–17220 of 61,297 articles
Advertisements