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 duplicates in an array using set() and filter() methods in JavaScript?
Finding duplicates in JavaScript arrays is a common task that can be accomplished using modern JavaScript methods. The Set() constructor and filter() method provide elegant solutions for removing duplicates without complex logic. Using Set() Method The Set() constructor automatically stores only unique values, making duplicate removal straightforward. When combined with the spread operator, it creates a new array with duplicates removed. Syntax let uniqueArray = [...new Set(originalArray)]; Example var dupNames = ['John', 'Ram', 'Rahim', 'Remo', 'Ram', 'Rahim']; var uniArr = [...new ...
Read MoreBuilt-in javascript constructors?
In this article, we are going to discuss about the Built-in JavaScript constructors with appropriate examples in JavaScript. JavaScript has provided some built-in constructors for native objects. These built-in functions include Object(), String(), Boolean(), RegExp(), Number(), Array(), Function(), and Date(). Note: We cannot include the Math object in those built-in constructors because Math is a global object. The new keyword cannot be used with Math. Let's understand this concept in a better way with the help of examples further in this article. String() Constructor The String() constructor converts values to strings. Here's an example demonstrating ...
Read MoreHow to pretty print json using javascript?
JavaScript Object Notation (JSON) is a standard format for storing and exchanging data. When working with JavaScript objects, displaying them in a readable format can be challenging, especially with complex nested structures. This article explores methods to pretty print JSON using JavaScript's built-in capabilities. The Problem with Default Object Display When you directly display a JavaScript object, it often appears as [object Object] or in a compact, unreadable format. Let's see this with a simple example: JSON Pretty Print Demo Output Console ...
Read MoreQuery-string encoding of a Javascript Object
The query string is made up of query parameters and used to send data to the server. This part of the URL is optional and needs to be constructed by the developer. This can be done using a native method called encodeURIComponent(). The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character. Using Object.keys() and map() Using ES6 features, objects can be query string encoded by combining Object.keys(), map(), and join() methods: let ...
Read MoreHow to create a constant array in JavaScript? Can we change its values? Explain.
To create a const array in JavaScript, we use the const keyword before the array name. While the array reference cannot be reassigned, individual elements can be modified. A const array prevents reassignment of the entire array but allows mutation of its contents. This is because const creates an immutable binding, not an immutable value. Syntax const arrayName = [element1, element2, element3]; Example: Creating and Modifying a Const Array Const Array Example ...
Read MoreHow to parse a string from a JavaScript array?
In JavaScript, you can convert an array to a string using several built-in methods. The most common approaches are toString(), join(), and JSON.stringify(). Using toString() Method The toString() method converts an array to a comma-separated string: Array to String Conversion Parse a string from a JavaScript array Convert Array to String ...
Read MoreHow to create a random number between a range JavaScript
Our job is to create a function, say createRandom, that takes in two arguments and returns a pseudorandom number between the range (max exclusive). Syntax const createRandom = (min, max) => { const diff = max - min; const random = Math.random(); return Math.floor((random * diff) + min); } Example const min = 3; const max = 9; const createRandom = (min, max) => { const diff = max - min; const random ...
Read MoreVerification if a number is Palindrome in JavaScript
A palindrome number reads the same forwards and backwards. In JavaScript, we can check if a number is palindrome without converting it to a string by mathematically extracting and comparing digits. Palindrome numbers are those numbers which read the same from both backward and forward. For example: 121 343 12321 Algorithm Approach The algorithm works by: Finding a factor to extract the first digit Comparing first and last digits Removing both digits and repeating until all digits are checked Example const isPalindrome = (num) => { ...
Read MoreCheck if value is empty in JavaScript
In JavaScript, checking if a value is empty is essential for form validation and data processing. You can check for empty strings, null values, and undefined variables using various approaches. Basic Empty Check The most common approach is to check for empty strings and null values: Check Empty Value USERNAME: ...
Read MoreExpressing numbers in expanded form - JavaScript
Suppose we are given a number 124 and are required to write a function that takes this number as input and returns its expanded form as a string. The expanded form of 124 is − '100+20+4' How It Works The algorithm converts each digit to its place value by multiplying it with the appropriate power of 10, then joins non-zero values with '+' signs. Example Following is the code − const num = 125; const expandedForm = num => { const numStr = String(num); ...
Read More