Articles on Trending Technologies

Technical articles with clear explanations and examples

Filter null from an array in JavaScript?

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

To filter null values from an array in JavaScript, use the filter() method. This method creates a new array containing only elements that pass a specified condition. Syntax array.filter(callback) Method 1: Using Boolean Constructor The simplest approach is to pass Boolean as the filter callback, which removes all falsy values including null, undefined, and empty strings. var names = [null, "John", null, "David", "", "Mike", null, undefined, "Bob", "Adam", null, null]; console.log("Before filtering:"); console.log(names); var filteredNames = names.filter(Boolean); console.log("After filtering null/falsy values:"); console.log(filteredNames); Before filtering: [ ...

Read More

Convert number to tens, hundreds, thousands and so on - JavaScript

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

We are required to write a function that, given a number, say, 123, will output an array − [100, 20, 3] Basically, the function is expected to return an array that contains the place value of all the digits present in the number taken as an argument by the function. We can solve this problem by using a recursive approach. Example Following is the code − const num = 123; const placeValue = (num, res = [], factor = 1) => { if(num){ ...

Read More

How to change the font size of a text using JavaScript?

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

In this tutorial, programmers will learn to change the font size of text using JavaScript. Many applications allow users to change the font size according to their requirements. We need to change the default font size using JavaScript to achieve that. Before we move ahead with the tutorial, let's learn what values we can assign to the font size. Different Values for Font Size We can assign the below values to the font size of any element. Every value changes the font size differently: xx-large | x-large | large | medium | small ...

Read More

How to return the "time" portion of the Date as a string using the current locale's conventions?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 164 Views

To return the "time" portion of the Date as a string, using the current locale's conventions, use the toLocaleTimeString() method. The toLocaleTimeString() method relies on the underlying operating system in formatting dates. It converts the date to a string using the formatting convention of the operating system where the script is running. For example, in the United States, the time appears in 12-hour format with AM/PM, whereas in many European countries, it appears in 24-hour format. Syntax date.toLocaleTimeString([locales], [options]) Parameters locales (optional): A string or array of strings representing locale identifiers (e.g., ...

Read More

How to set the indentation of the first line of text with JavaScript?

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

In this tutorial, we will learn how to set the indentation of the first line of text with JavaScript. The indentation of the first line of a text is a common way to start a new paragraph. To set the indentation, use the textIndent property. To set the indentation of the first line of text with JavaScript, we will discuss two different ways − Using the style.textIndent Property Using the style.setProperty Method Using the style.textIndent Property The style.textIndent property of an element is used to set the ...

Read More

How to work with JavaScript Drag and drop for touch devices?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 6K+ Views

JavaScript drag and drop functionality provides an intuitive way to move elements within web pages. While the HTML5 Drag and Drop API works well on desktop, touch devices require additional handling to ensure proper functionality. Basic Drag and Drop Concepts To make an element draggable in HTML5, add the draggable="true" attribute to the element. By default, images and text selections are draggable, but other elements need this attribute. Drag me Drag and Drop Events The drag and drop process involves two sets of events: Events on draggable elements: dragstart - Fires ...

Read More

HTML5 audio control stop button

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 1K+ Views

HTML5 audio elements don't have a built-in stop button, but you can create one by combining the pause() method with resetting the currentTime property. Basic Stop Function To stop audio playback, pause the audio and reset its current time to zero: Stop function stopAudio() { var myPlayer = document.getElementById('myAudio'); myPlayer.pause(); myPlayer.currentTime = 0; } Complete Example with Play/Stop Controls Play Stop var audio = document.getElementById('audioPlayer'); function playAudio() { ...

Read More

ArrayBuffer.isView() function in JavaScript

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

The ArrayBuffer.isView() static method determines whether a given value is an ArrayBuffer view. ArrayBuffer views include typed arrays (like Int32Array, Float64Array) and DataView objects. Syntax ArrayBuffer.isView(value) Parameters value: The value to test whether it's an ArrayBuffer view. Return Value Returns true if the value is an ArrayBuffer view (typed array or DataView), false otherwise. Example 1: Testing Typed Arrays ArrayBuffer.isView() Example // Create typed arrays ...

Read More

What is the use of Object.is() method in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 258 Views

The Object.is() method determines whether two values are strictly equal, providing more precise comparison than the regular equality operators. Syntax Object.is(value1, value2) Parameters value1: The first value to compare value2: The second value to compare Return Value Returns true if both values are the same, false otherwise. How Object.is() Determines Equality Two values are considered the same when they meet these criteria: Both are undefined or both are null Both are true or both ...

Read More

How to clone an array using spread operator in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

In this article, we are going to discuss how to use the spread operator to clone an array in JavaScript. Cloning is the process of copying one array into another array. Previously, the slice() method was used to clone an array, however, ES6 now provides the spread operator (...) to simply clone an array. What is Array Cloning? An Array is a data structure in JavaScript that can hold multiple values at once. Cloning involves copying an array's elements to create a new independent array. ...

Read More
Showing 16691–16700 of 61,297 articles
Advertisements