Articles on Trending Technologies

Technical articles with clear explanations and examples

Finding elements whose successors and predecessors are in array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 524 Views

We are required to write a JavaScript function that takes in an array of integers as the first and the only argument. The function should construct and return a new array that contains all such elements from the original array whose successor and predecessor are both present in the array. This means, if any element num is in the original array, it should be included in the result array if and only if num - 1 and num + 1 are also present in the array. For example, if the input array is: const arr = ...

Read More

Numbers obtained during checking divisibility by 7 using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 721 Views

In mathematics, we can check if a number is divisible by 7 using a special algorithm. For any number of the form 10a + b (where a is all digits except the last, and b is the last digit), we calculate a - 2b. If this result is divisible by 7, then the original number is also divisible by 7. We repeat this process until we get a number with at most 2 digits, since it's easy to check divisibility by 7 for such small numbers. This article demonstrates how to implement this algorithm in JavaScript and count the ...

Read More

Count of pairs in an array that have consecutive numbers using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 510 Views

Problem We need to write a JavaScript function that takes an array of integers and returns the count of consecutive pairs. A consecutive pair consists of two adjacent elements in the array where one number is exactly one more than the other. Understanding Consecutive Pairs Two numbers are consecutive if their absolute difference is 1. For example, (5, 6), (8, 7), and (-3, -4) are all consecutive pairs. Solution We'll iterate through the array in steps of 2, treating each pair of adjacent elements as a potential consecutive pair: const arr = [1, ...

Read More

What is the FlatList component and how to use it in React Native?

Shilpa S
Shilpa S
Updated on 15-Mar-2026 2K+ Views

FlatList is a high-performance, scrollable list component in React Native that efficiently renders large datasets. It offers header and footer support, multiple column support, comes with vertical/horizontal scrolling, lazy loading, and virtualization for optimal performance. Here are some important features of FlatList: Virtualized rendering for performance optimization Scroll loading and lazy rendering ScrollToIndex support for programmatic scrolling Header and footer component support Multiple column support Cross-platform compatibility Configurable viewability ...

Read More

How to enable centered scaling on a canvas using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 1K+ Views

In this article, we are going to learn how to enable centered scaling on a canvas using FabricJS. In FabricJS, an object gets transformed proportionally when dragged from the corners. We can use the centeredScaling property to use the center as the origin of transformation. Syntax new fabric.Canvas(element: HTMLElement|String, { centeredScaling: Boolean }: Object) Parameters element − This parameter is the element itself which can be derived using Document.getElementById() or the id of ...

Read More

How to convert a string of any base to an integer in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 585 Views

An integer can be represented in various formats in programming languages such as Binary (base 2), Decimal (base 10), Hexadecimal (base 16), and Octal (base 8). A Binary number consists of two digits only (0 & 1), whereas a decimal consists of digits from 0 to 9. We can convert a string to an integer using the parseInt() method. When the integer is represented in a different base, we need to pass the base parameter to decode it correctly. Syntax parseInt(string_value, base) parseInt(string_value) // Defaults to base 10 Parameters ...

Read More

How to create a revealing sidebar using HTML, CSS, and JavaScript?

Kalyan Mishra
Kalyan Mishra
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we will create a revealing sidebar using HTML, CSS, and JavaScript. A revealing sidebar is a navigation menu that slides in and out of view when toggled, providing a clean and modern user interface. Approach We will follow these steps to create our revealing sidebar: STEP 1 − Create the HTML structure with navigation elements including a hamburger menu icon and sidebar items. STEP 2 − Style the elements using CSS to position the sidebar and add smooth transitions. STEP 3 − Add JavaScript ...

Read More

Set object property in an array true/false, whether the id matches with any id from another array of objects in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 781 Views

In JavaScript, you often need to compare two arrays of objects and set a property (like matches) to true or false based on whether their IDs match. This is useful for data processing, filtering, and UI state management. An object in JavaScript is a collection of key-value pairs that represent properties and their values. Arrays are ordered lists that can store multiple values, including objects, and are accessed using numeric indices starting from 0. Syntax Basic array syntax: const arrayName = [item1, item2, ...]; Method 1: Using reduce() and map() The reduce() ...

Read More

Set PIN validation with JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 2K+ Views

In this article, we will discuss how to set up PIN validation using JavaScript. We will cover creating prompts for users to enter their PIN number, validating input against stored values, and returning appropriate responses based on the validation result. Data validation is the procedure used to ensure that user input is accurate, reliable, and clean. PIN validation typically checks the length, format, and data type to ensure the PIN contains only digits and meets specific requirements. We can validate PINs based on length (usually 4 or 6 digits) and ensure the input contains only numeric characters. Let's ...

Read More

Manipulating objects in array of objects in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 4K+ Views

In JavaScript, manipulating objects within an array of objects is a common task. JavaScript provides several built-in array methods like map(), filter(), find(), and slice() to efficiently handle these operations. What is Object Manipulation in Arrays? Object manipulation in arrays involves three main operations: Updating - Modifying existing object properties Filtering - Selecting objects based on criteria Adding - Creating new objects or properties JavaScript provides methods like map(), filter(), find(), slice(), sort(), reduce(), and others to perform these manipulations efficiently. Original Array ...

Read More
Showing 15761–15770 of 61,297 articles
Advertisements