Javascript Articles

Page 235 of 534

How to convert JSON results into a date using JavaScript?

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

JSON is a powerful data format to exchange data from server to client and vice versa. Many times JSON data is received in a String format and we need to convert it to a usable JSON object. In this process, it's an important requirement to convert string data into Date format. In this article, we will learn how to convert JSON results into a Date string using JavaScript. The JSON objects contain the date like this − { name: "John", time: '/Date(1559072200000)/' } And the result will be − ...

Read More

How to convert Map keys to an array in JavaScript?

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

In JavaScript, you can convert a Map's keys to an array using several methods. The most common approaches are using Array.from(), the spread operator, or a for...of loop with Map.keys(). Given a JavaScript Map, the task is to extract all keys and create an array from them. Here's an example: Given Map: Map { 1 => "India", 2 => "Russia", 3 => "USA", 4 => "Japan", 5 => "UK" } Resulting Array: [1, 2, 3, 4, 5] There are multiple ways to achieve this conversion: Using Array.from() and Map.keys() method ...

Read More

How to convert NaN to 0 using JavaScript?

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

We can use the logical OR operator, double bitwise NOT operator, strict equality operator, or the isNaN() function to convert NaN to 0 using JavaScript. NaN in JavaScript means Not a Number, whose type is Number but actually, it is not a number. In this article, we will learn different approaches to convert NaN to 0. Using the Logical OR (||) Operator Using the Double Tilde (~~) Operator Using the Strict Equality (===) Operator Using the isNaN() function Using the Logical OR (||) Operator ...

Read More

How to convert special characters to HTML in Javascript?

Saurabh Anand
Saurabh Anand
Updated on 15-Mar-2026 6K+ Views

Special characters like , and & have special meaning in HTML and can break your webpage if not properly escaped. JavaScript provides several methods to convert these characters into their HTML entity equivalents. Why Convert Special Characters to HTML? When displaying user input or dynamic content on a webpage, special characters can cause problems. For example, if you want to display "" as text, the browser might interpret it as an actual HTML tag. Converting these characters to HTML entities like ensures they display as intended text. Common characters that need escaping: ...

Read More

How to convert UTC date time into local date time using JavaScript?

Saurabh Anand
Saurabh Anand
Updated on 15-Mar-2026 32K+ Views

Timezone handling is an essential component of every web application. The time that is recorded in the backend is usually in UTC format. When it is displayed to the user, however, it must be converted to the user's local time. This is possible with JavaScript. We'll look at how to use JavaScript to convert UTC date time to local date time in this blog. JavaScript Date Object JavaScript includes a "Date" object that allows us to work with dates and times. The Date object includes various methods for working with dates and times, including: ...

Read More

How to count text lines inside of a DOM element?

Saurabh Anand
Saurabh Anand
Updated on 15-Mar-2026 3K+ Views

Introduction The DOM (Document Object Model) is an API for HTML and XML documents that provides programmers control over a webpage's structure, appearance, and content. Counting text lines within DOM elements is useful for layout calculations, pagination, and content management. This article explores three methods to count text lines in DOM elements using JavaScript. Method 1: Using the scrollHeight Property The scrollHeight property returns the total height of an element, including content hidden by overflow. We can calculate the number of lines by dividing scrollHeight by the height of a single line of text. ...

Read More

How to count the number of times a button is clicked using JavaScript?

Saurabh Anand
Saurabh Anand
Updated on 15-Mar-2026 18K+ Views

Tracking button clicks is a common task in JavaScript and can be achieved by using the addEventListener() method. By adding an event handler to the button element and incrementing a variable each time the button is pressed, we can keep track of button clicks. We can display the count to users and even persist clicks using localStorage so they remain after browser closure. This technique is essential for interactive web applications like calculators, games, or analytics tracking. Let's explore different methods to count button clicks effectively. Creating a Basic Button First, we need a button element on ...

Read More

How to create 3D Geometries in webGL and p5.js?

Saurabh Anand
Saurabh Anand
Updated on 15-Mar-2026 941 Views

Creating 3D geometries in WebGL and p5.js enables developers to build interactive and visually compelling web applications. With built-in functions for basic shapes, texture mapping, and transformations, both libraries provide powerful tools for 3D graphics development. Understanding WebGL vs p5.js for 3D Graphics WebGL is a low-level graphics API that provides direct access to the GPU, while p5.js offers a higher-level, artist-friendly interface. For complex 3D applications, Three.js (built on WebGL) is often preferred, whereas p5.js excels in creative coding and educational contexts. Creating Basic 3D Shapes Using Three.js (WebGL-based) Three.js simplifies WebGL by providing ...

Read More

How to create the previous and next buttons and non-working on the end positions using JavaScript?

Dishebh Bhayana
Dishebh Bhayana
Updated on 15-Mar-2026 1K+ Views

We can create previous and next buttons that are disabled at their end positions using vanilla JavaScript. JavaScript allows us to control and manipulate DOM elements easily. Here, we will create navigation buttons and change an HTML element's content depending on which button is clicked. Example 1: Counter with Disabled States In this example, we will create "Next" and "Previous" buttons that increment and decrement a counter. The buttons will be disabled when they reach their extreme positions (0 for Previous and 5 for Next). Previous and Next Buttons with ...

Read More

How to create regular expression only accept special formula?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 1K+ Views

Regular expressions are powerful patterns used to validate and match specific text formats. In this tutorial, we'll learn how to create regular expressions that validate mathematical formulas containing various operators and formats. Basic Formula Validation Let's start with a simple regular expression that accepts basic mathematical formulas with addition and subtraction operators. Syntax let regex = /^\d+([-+]\d+)*$/g; This regex accepts formulas like "10-13+12+23" with no spaces between operators and numbers. Regular Expression Breakdown ^ – Represents the start of the string \d+ – Matches one or more digits at the ...

Read More
Showing 2341–2350 of 5,340 articles
« Prev 1 233 234 235 236 237 534 Next »
Advertisements