Articles on Trending Technologies

Technical articles with clear explanations and examples

Usage of margin-top property with CSS

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

The margin-top property specifies the top margin of an element in CSS. It creates space above an element, pushing it away from adjacent elements or the container's edge. Syntax margin-top: value; Values Length: Fixed values like 10px, 2em, 1rem Percentage: Relative to parent's width (e.g., 10%) auto: Browser calculates automatically inherit: Inherits from parent element Example: Fixed Values ...

Read More

How to know whether a value is searched in Javascript sets?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 290 Views

In JavaScript, sets are collections of unique values. Sometimes you need to check whether a specific element exists inside a set. In this article, we will explore different techniques to verify element presence in JavaScript sets. Using for Loop (Manual Search) You can search for an element by iterating through the set and comparing each element with the target value. If found, return true; otherwise, return false after checking all elements. HTML Console Output Console Output: ...

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

Explain 'dotAll' flag for regular expressions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 371 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 338 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 658 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
Showing 17211–17220 of 61,299 articles
Advertisements