Articles on Trending Technologies

Technical articles with clear explanations and examples

Finding astrological signs based on birthdates using JavaScript

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

We are required to write a JavaScript function that takes in a date object and returns the astrological sign related to that birthdate based on zodiac date ranges. Understanding Zodiac Signs Each zodiac sign corresponds to specific date ranges throughout the year. The challenge is handling the transition dates correctly, especially for signs that span across months. Example Following is the code: const date = new Date(); // as on 2 April 2021 const findSign = (date) => { const days = [21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22]; const signs = ["Aquarius", "Pisces", "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn"]; let month = date.getMonth(); let day = date.getDate(); if(month == 0 && day

Read More

Length of shortest unsorted array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 232 Views

We are required to write a JavaScript function that takes in an array of numbers and finds the length of the shortest continuous subarray that, when sorted, makes the entire array sorted in ascending order. Our function needs to find the length of one continuous subarray such that if we only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. Problem Example For example, if the input array is: const arr = [3, 7, 5, 9, 11, 10, 16]; console.log("Original array:", arr); Original array: ...

Read More

How to apply function against an accumulator and each key of object in JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 553 Views

In JavaScript, we can use the reduce() method to apply a function against an accumulator and each element of an array (from left to right). This method is particularly useful when working with arrays of objects where we need to process each key-value pair. The reduce() method is called on a given array and takes a callback function as its first argument. Please refer to Array reduce() for more details. Syntax array.reduce(callback[, initialValue]) Parameters callback − Function to execute on each value in the array. ...

Read More

Fabric.js – How to check if an Image object is fully contained within the area of another object?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 754 Views

In this tutorial, we are going to learn how to check if an Image object is fully contained within the area of another object using FabricJS. We can create an Image object by creating an instance of fabric.Image. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to check if an Image object is fully contained within the area of another object, we use the isContainedWithinObject method. Syntax isContainedWithinObject(other: Object, absolute: Boolean, calculate: Boolean): Boolean Parameters other ...

Read More

Why do we Use JavaScript in HTML?

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

JavaScript transforms static HTML pages into dynamic, interactive websites. When a website displays timely content updates, interactive maps, animated visuals, or responsive user interfaces, JavaScript is the technology making it happen. As a scripting language, JavaScript adds advanced functionality to websites and represents the third essential layer of modern web development. The Three Layers of Web Development Modern web pages are built using three complementary technologies that work together: HTML (Structure): The markup language that defines the content structure and meaning. HTML creates paragraphs, headings, lists, and embeds images and videos into web ...

Read More

How to add a clipping area on a Polygon using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 950 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. A clipping path restricts the area to which fill or stroke is applied in a Polygon object. Therefore, the parts of the polygon which lie outside the clipping path, will not be drawn. In order to add a clipping area we use the clipPath property. ...

Read More

Fetch specific values from array of objects in JavaScript?

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

Fetching specific values from an array of objects is a common JavaScript task. This article demonstrates multiple approaches to filter and extract data based on specific criteria. Sample Data Let's start with an array of employee objects: const details = [ { employeeFirstName: "John", employeeLastName: "Doe" }, { employeeFirstName: "David", employeeLastName: "Miller" ...

Read More

Filtering out the non-unique value to appear only once in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 254 Views

We have an array that contains some duplicate values appearing multiple times. We need to extract only the elements that appear more than once in the array, but show each duplicate element only once in the result. const arr = [1, 4, 3, 3, 1, 3, 2, 4, 2, 1, 4, 4]; console.log("Original array:", arr); Original array: [1, 4, 3, 3, 1, 3, 2, 4, 2, 1, 4, 4] We need to write a JavaScript function that filters out elements that appear multiple times and returns each duplicate element only once. For ...

Read More

Merge JSON array date based JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 801 Views

When working with JSON arrays containing objects with date properties, you often need to merge objects that share the same date. This is common when combining data from different sources or consolidating time-series data. Suppose we have the following array of objects: const arr = [ { "date": "2010-01-01", "price": 30 }, { "date": "2010-02-01", ...

Read More

Find what numbers were pressed to get the word (opposite of phone number digit problem) in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 206 Views

The mapping of the numerals to alphabets in the old keypad type phones used to be like this: const mapping = { 1: [], 2: ['a', 'b', 'c'], 3: ['d', 'e', 'f'], 4: ['g', 'h', 'i'], 5: ['j', 'k', 'l'], 6: ['m', 'n', 'o'], 7: ['p', 'q', 'r', 's'], 8: ['t', 'u', 'v'], 9: ['w', 'x', 'y', 'z'] }; console.log(mapping); { '1': [], '2': [ 'a', 'b', 'c' ], '3': ...

Read More
Showing 16511–16520 of 61,297 articles
Advertisements