Articles on Trending Technologies

Technical articles with clear explanations and examples

Convert buffer to readable string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 795 Views

In Node.js, buffers store binary data and need to be converted to strings for readability. The toString() method with encoding parameters handles this conversion. What is a Buffer? A Buffer is a Node.js object that represents a fixed-size chunk of memory allocated outside the JavaScript heap. It's used to handle binary data directly. Basic Buffer to String Conversion Use the toString() method with the appropriate encoding. UTF-8 is the most common encoding for text data. // Create a buffer from string var actualBufferObject = Buffer.from('[John Smith]', 'utf8'); console.log("The actual buffer object:"); console.log(JSON.stringify(actualBufferObject)); // ...

Read More

Retrieve user id from array of object - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 977 Views

Suppose, we have an array of objects where the user names are mapped to some unique ids like this − const arr = [ {"4": "Rahul"}, {"7": "Vikram"}, {"6": "Rahul"}, {"3": "Aakash"}, {"5": "Vikram"} ]; As apparent in the array, same names can have more than one ids but same ids cannot be used to map two different names. We are required to write a JavaScript function that takes in one such array as the first argument and a name ...

Read More

How to extract the number of minutes from current time in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

JavaScript uses timestamps based on Unix time (milliseconds since January 1, 1970 UTC) to handle dates and times. While humans understand time in hours and minutes, JavaScript provides built-in methods to extract specific time components from Date objects. In this tutorial, we will learn how to extract the number of minutes from the current time in JavaScript using the getMinutes() method. Date Object Methods The JavaScript Date object provides several methods to extract time components: getHours() − Returns the current hour (0-23) in 24-hour format getMinutes() − Returns the current minutes (0-59) getSeconds() − Returns ...

Read More

How null is converted to Number in JavaScript?

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

In JavaScript, null is a primitive value that represents the intentional absence of any object value. When null is converted to a number, it becomes 0. This article explores various methods to convert null to a number in JavaScript. Using Number() Method Using Logical OR (||) Using the ~~ operator Using Ternary Operator Using arithmetic operations Using the Number() Method The Number() method is the most straightforward way to convert null to a number. It explicitly converts null to 0. Syntax Number(null) Example ...

Read More

How to set the right margin of an element with JavaScript?

Jai Janardhan
Jai Janardhan
Updated on 15-Mar-2026 677 Views

Use the marginRight property in JavaScript to set the right margin of an element. This property accepts values in pixels, percentages, or other CSS units. Syntax element.style.marginRight = "value"; Example #myID { border: 2px solid #000000; background-color: #f0f0f0; padding: 10px; } ...

Read More

Reset HTML input style for checkboxes to default in IE

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

Resetting HTML input styles for checkboxes to their default native appearance can be challenging in Internet Explorer. Some browsers don't allow complete style resets for form elements. The Problem When you apply global CSS styles to inputs, checkboxes may inherit unwanted styling that you cannot easily reset to their original native appearance. Method 1: Target Specific Input Types Style only the input types you want to modify, excluding checkboxes: input[type="text"], input[type="password"], input[type="email"], input[type="number"] { border: 2px solid green; padding: 5px; } Method 2: ...

Read More

Open a file browser with default directory in JavaScript and HTML?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 1K+ Views

Opening a file browser with a default directory is not possible in JavaScript due to security restrictions. Web browsers prevent websites from accessing or setting specific file system paths to protect user privacy and system security. Why Default Directory Setting is Restricted Browsers block this functionality for several security reasons: Prevents websites from accessing sensitive system directories Protects user privacy by hiding file system structure Avoids potential security exploits through path manipulation Directory paths may not exist on different operating systems Standard File Input Behavior The HTML file input always opens in the ...

Read More

Creating a hash table using Javascript

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

A hash table (also called hash map) is a data structure that stores key-value pairs and provides fast lookup, insertion, and deletion operations. In JavaScript, we can implement a hash table using arrays and a hash function to map keys to array indices. Basic Hash Table Structure Let's create a hash table class with collision resolution using chaining. We'll use an array of arrays where each index can hold multiple key-value pairs in case of hash collisions. class HashTable { constructor() { this.container = ...

Read More

JavaScript Cursor property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 238 Views

The JavaScript cursor property sets or returns the cursor type that will be displayed when hovering over an element. This property allows you to change the mouse cursor appearance dynamically using JavaScript. Syntax element.style.cursor = "cursorType"; Example: Changing Cursor on Button Click body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { ...

Read More

What are common HTML Events supported by JavaScript?

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 231 Views

JavaScript supports numerous HTML events that allow you to create interactive web pages. These events are triggered by user actions like clicks, keyboard input, or changes to HTML elements. Mouse Events Mouse events are the most commonly used events for creating interactive interfaces: Event Description ...

Read More
Showing 18051–18060 of 61,297 articles
Advertisements