Articles on Trending Technologies

Technical articles with clear explanations and examples

How to get only the first BOT ID from thes JavaScript array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 148 Views

When working with an array of objects in JavaScript, you often need to access specific properties from the first element. Let's explore how to get the first BOT ID from an array of user records. Sample Data Structure Consider an array of objects where each object contains a BOTID and Name: let objectArray = [ { BOTID: "56", Name: "John" }, { BOTID: "57", Name: "David" }, { BOTID: "58", Name: "Sam"}, { BOTID: "59", Name: "Mike" }, ...

Read More

Calculating excluded average - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 223 Views

In JavaScript, you may need to calculate the average of specific values in an array of objects based on certain conditions. This tutorial shows how to compute the average of values where a boolean flag indicates they should be included in the calculation. Problem Description Given an array of objects with val and canUse properties, we need to calculate the average of val values only for objects where canUse is true. const arr = [ {val: 56, canUse: true}, {val: 16, canUse: true}, {val: 45, canUse: true}, ...

Read More

How to subtract days from a date in JavaScript?

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

In JavaScript, you can subtract days from a date using built-in Date methods. The most common approaches are using setTime() with getTime() for millisecond-based calculation, or setDate() with getDate() for simpler day-based arithmetic. Following are the methods we can use to subtract days from a date in JavaScript: Using the setTime() and getTime() methods Using the setDate() and getDate() methods Using setTime() and getTime() Methods The setTime() method sets a date by milliseconds since ...

Read More

How null is converted to Boolean in JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 7K+ Views

In JavaScript, null is a primitive value that represents an intentional absence of any object value. When converting null to Boolean, it always evaluates to false because null is considered a falsy value in JavaScript. Understanding Falsy Values In JavaScript, null is one of the falsy values along with undefined, 0, "" (empty string), NaN, and false. All falsy values convert to false when used in Boolean contexts. Using the Boolean() Function The Boolean() function converts any value to its Boolean equivalent. For null, it always returns false. Syntax Boolean(null) Example ...

Read More

How to offset an outline and draw it beyond the border edge with JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 269 Views

To offset an outline in JavaScript, use the outlineOffset property. This CSS property allows you to draw the outline beyond the border edge, creating space between the element's border and its outline. Syntax element.style.outlineOffset = "value"; The value can be specified in pixels (px), ems (em), or other CSS length units. Positive values move the outline away from the border, while negative values move it inward. Example #box { ...

Read More

Circle Collision Detection HTML5 Canvas

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

Circle collision detection in HTML5 Canvas involves checking whether two circles intersect by calculating the distance between their centers and comparing it to the sum of their radii. How Circle Collision Detection Works Two circles collide when the distance between their centers is less than or equal to the sum of their radii. If the distance is greater, they don't collide. distance r1 r2 Basic Formula The collision detection formula uses the Pythagorean theorem to calculate distance: distance = Math.sqrt((x2 - x1)² + (y2 - y1)²) collision = distance

Read More

Node in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 273 Views

In JavaScript tree data structures, a node is the fundamental building block that contains data and references to other connected nodes. For binary trees, each node has three essential properties: the data it stores and references to its left and right child nodes. Node Structure A typical tree node contains the following components: data − Stores the actual value or information in the node left − Reference to the left child node right − Reference to the right child node Creating a Node Class ...

Read More

Describe pass by value and pass by reference in JavaScript?

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

JavaScript passes data to functions in two ways: pass by value for primitives (numbers, strings, booleans) and pass by reference for objects and arrays. Understanding this distinction is crucial for avoiding unexpected behavior in your code. Pass by Value In pass by value, a function receives a copy of the variable's value. Changing this copy inside the function doesn't affect the original variable. JavaScript primitives (numbers, strings, booleans, null, undefined) are always passed by value. Example let a = 1; let change = (val) ...

Read More

How to toggle a boolean using JavaScript?

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

In this tutorial, we will learn how to toggle a boolean value in JavaScript. In addition to this, we will also learn how we can use it for various web application features that require toggling a certain piece of state or value. Toggling a boolean in JavaScript entails altering its value from true to false or vice versa. Toggling booleans can be helpful in a variety of situations, such as changing a boolean value to initiate an action or to toggle between states or the visibility of an element. Toggling can be implemented using different methods like the ...

Read More

Getting an HTML H1 value to JavaScript variable?

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

To get the value of an HTML H1 element into a JavaScript variable, you can use document.getElementById().innerHTML to access the text content inside the heading. Basic Syntax var headingText = document.getElementById('elementId').innerHTML; Example: Getting H1 Content Let's say we have the following H1 heading with an id: This is the demo program of JavaScript Here's how to get the H1 value using JavaScript: Getting H1 Value ...

Read More
Showing 18141–18150 of 61,297 articles
Advertisements