Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Merge two objects in JavaScript ignoring undefined values
When merging two objects in JavaScript, you may want to ignore undefined values to avoid overwriting valid data. The spread operator alone doesn't handle this logic, so we need a custom approach. The Problem Consider these two objects where some properties have undefined values: const A = { activity: 'purchased', count: undefined, time: '09:05:33' }; const B = { activity: 'purchased', count: '51', time: undefined }; // Simple spread operator overwrites values const simpleSpread = { ...A, ...B }; console.log("Simple spread:", simpleSpread); Simple spread: { activity: 'purchased', count: '51', time: undefined } ...
Read MoreHow to convert a currency string to a double with jQuery or JavaScript?
Converting currency strings to numerical values is essential in web applications for calculations and data processing. This article demonstrates how to convert currency strings to doubles using JavaScript methods. There are two popular approaches to convert currency strings into numerical values using JavaScript built-in methods. We'll explore both methods with practical examples. Method 1: Using substring() and charCodeAt() This approach uses a loop to iterate through each character, checking if it's numeric using Unicode values: Use the charCodeAt() method to get the Unicode value of each character Use the substring() method to extract the numeric ...
Read MoreIs it possible to create a new data type in JavaScript?
The task we are going to perform in this article is to explore whether it's possible to create a new data type in JavaScript. For instance, let's consider we have a variable student: var student = "username"; console.log(typeof student); string Now, I want to declare a custom type for that variable and print that in the output. Let's dive into the article to learn more about creating a new data type in JavaScript. Can You Create Custom Data Types? Yes, it is possible to create custom data types in JavaScript using ...
Read MoreJoin two objects by key in JavaScript
When working with related data structures, you often need to join objects from different arrays based on matching keys. This is common when dealing with parent-child relationships or normalized data. Suppose we have two arrays - one containing child objects and another containing parent objects: const child = [{ id: 1, name: 'somename', parent: { id: 2 }, }, { id: 2, name: 'some child ...
Read MoreFlattening a deeply nested array of literals in JavaScript
We are required to write a JavaScript function that takes in a nested array of literals as the only argument. The function should construct a new array that contains all the literal elements present in the input array but without nesting. For example − If the input array is − const arr = [ 1, 3, [5, 6, [7, [6, 5], 4], 3], [4] ]; Then the output array should be − [1, 3, 5, 6, 7, 6, 5, 4, 3, 4] Method 1: Recursive Approach ...
Read MoreFinding the maximum number using at most one swap in JavaScript
We are required to write a JavaScript function that takes in a number as the first and the only argument. The task of our function is to perform at most one swap between any two digits of the number and yield the maximum possible number. If the number is already the maximum possible number, we should return the number itself. For example, if the input number is: const num = 1625; Then the output should be: const output = 6125; We swapped 1 and 6, and this is the only ...
Read MoreCounting number of triangle sides in an array in JavaScript
Problem We are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument. The task of our function is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. For example, if the input to the function is − const arr = [2, 2, 3, 4]; Then the output should be − const output = 3; Triangle Validity Rule For three sides to ...
Read MoreHow to lock the horizontal skewing of Rectangle using FabricJS?
In this tutorial, we are going to learn how to lock the horizontal skewing of a Rectangle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a rectangle object in the canvas, we can also specify whether we want to stop skewing an object horizontally. This can be done by using the lockSkewingX property. Syntax new fabric.Rect({ lockSkewingX : Boolean }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our rectangle. Using this parameter, properties such as colour, ...
Read MoreHow to set the style of individual characters in Text using FabricJS?
In this tutorial, we are going to learn how to set the style of individual characters in Text using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. Similarly, we can also set the style of individual characters by using the styles property. Syntax new fabric.Text(text: String , { styles: Object }: ...
Read MoreHow to set the background colour of Line in FabricJS?
In this tutorial, we are going to learn how to set the background colour of Line using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. The backgroundColor property allows us to assign a colour to our object's background. Syntax new fabric.Line( points: ...
Read More