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
How to find the biggest number in an array around undefined elements? - JavaScript
We are required to write a JavaScript function that takes in an array that contains some numbers, some strings and some falsy values. Our function should return the biggest Number from the array. For example − If the input array is the following with some undefined values − const arr = [23, 'hello', undefined, null, 21, 65, NaN, 1, undefined, 'hii']; Then the output should be 65 Solution Approach We'll filter out non-numeric values and find the maximum among valid numbers. The key is to properly identify numeric values while handling ...
Read MoreJavaScript Insert space after every two letters in string?
In this article we are going to learn about how to insert space after every two letters in string. Before we jump into the article let's have a quick view on the strings in JavaScript. A sequence of one or more characters—which could be numbers, or symbols—is referred to as a string. Strings are immutable primitive data types in JavaScript, which means they cannot be changed. Let's dive into the article to learn more about inserting a space after every two letters in strings. For this, we'll explore multiple approaches using replace() with regular expressions and other methods. ...
Read MoreHow to generate array key using array index – JavaScript associative array?
In JavaScript, you can create associative arrays (objects) using array indices as keys. This is useful for mapping array elements to their positions or creating key-value pairs from existing arrays. Using forEach() Method The forEach() method provides access to both the element and its index, allowing you to create dynamic object properties: var result = {}; var names = ['John', 'David', 'Mike', 'Sam', 'Bob', 'Adam']; names.forEach((nameObject, counter) => { var generatedValues = { [nameObject]: counter }; Object.assign(result, generatedValues); }); console.log(result); { John: 0, ...
Read MoreRetrieve property value selectively from array of objects in JavaScript
When working with arrays of objects in JavaScript, you often need to extract specific property values based on certain conditions. This tutorial shows how to retrieve property values selectively from an array of objects. Suppose we have an array of objects like this: const arr = [ { id : "23", name : "Item 1", isActive : true}, { id : "25", name : "Item 2", isActive : false}, { id : "26", name : "Item 3", isActive : false}, { id : "30", name ...
Read MoreRemoving all non-alphabetic characters from a string in JavaScript
Non-alphabetic characters are any characters that are not part of the alphabet, and the strings are a data type that represents a sequence of characters or text. Working with strings is a basic task in JavaScript, and one common task is removing all non-alphabetic characters from a string. In this article, we will understand how to remove all non-alphabetic characters from a string. Understanding the Problem Suppose we have a string saying "he@656llo wor?ld". We want to remove all digits, punctuation, whitespace, and special characters from the given string. For example: Input string we have: "he@656llo wor?ld" ...
Read MoreDistance of nearest 0 in binary matrix in JavaScript
A binary matrix is an array of arrays containing only 0 or 1. We are required to write a JavaScript function that takes in a binary matrix as the only argument. Our function should create a new matrix containing the same number of rows and columns, and for each element of the original matrix the resulting matrix should contain that element's nearest distance from 0 in the original matrix. We have to keep in mind that while calculating distance it can move either horizontally or vertically and not diagonally. And it's guaranteed that the matrix contains at least ...
Read MoreConstructing an array of addition/subtractions relative to first array element in JavaScript
We are required to write a JavaScript function that takes in an array of positive integers. Our function should map this array to an array of string integers. The array should contain the number we should add/subtract to the first element to achieve the corresponding element. Problem For example, if we have: [4, 3, 6, 2] We need to calculate the difference between each element and the first element (4): 4 - 4 = 0 → "+0" 3 - 4 = -1 → "-1" 6 - 4 = 2 → "+2" 2 ...
Read MoreHow to avoid jQuery function conflict with any other JavaScript library
In this tutorial, we will learn how to avoid jQuery function conflict with any other JavaScript library. For the jQuery function, the $ symbol is simply an identifier. A $ followed by a selector indicates that it is a jQuery selector. It is given a shorter identification as $ to save time while writing longer syntax. It includes all of the functions needed by a jQuery object, such as animation(), show(), hide(), CSS, and many others. Furthermore, $ is superior in terms of memory to jQuery because $ takes a byte while jQuery uses 6 bytes for the same ...
Read MoreFabricJS – How to set the colour of the controlling corners of a Line?
In this tutorial, we are going to learn about how to set the colour of the controlling corners 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 cornerColor property allows us to manipulate the colour of the controlling corners when the object ...
Read MoreHow to use polyfill in JavaScript?
The developers of JavaScript always keep adding new features to the JavaScript language to improve performance and add better functionalities. Sometimes, it happens that new features don't support by the old browser versions. For example, the exponential operator is introduced in ES7, and the trailing comma in the object is also valid in ES7. Now, while developing the application, we have used the exponential operator in the application. It will work with the newer versions of the browser, but if someone is using a very old version of the browser, they can get errors like the exponential operator is ...
Read More