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
Difference between numbers and string numbers present in an array in JavaScript
In JavaScript, arrays can contain both numbers and string representations of numbers. This article demonstrates how to differentiate between these types and perform different operations based on their type. Problem We need to create a JavaScript function that takes a mixed array of numbers and string representations of integers. The function should add up all numeric values and subtract the sum of string numeric values from this total. Approach We'll use typeof to identify data types and the unary plus operator (+) to convert strings to numbers while checking if they're valid numeric strings. Example ...
Read MoreDifference between Local Storage, Session Storage, and Cookies in JavaScript
JavaScript provides three mechanisms for storing data on the client − cookies, session storage, and local storage. Each one has advantages and disadvantages. Local storage is the most recent mechanism. It allows for larger amounts of data to be stored, but the data is not deleted when the browser is closed. Local storage is useful for storing data that the user will need to access later, such as offline data. Session storage is similar to cookies, but the data is only stored for the current session. This means that the data will be deleted when the user closes ...
Read MoreHow to swap the key and value of JSON element using JavaScript?
Here, we will learn to swap the key and value of JSON elements using JavaScript. In JavaScript, an object stores key-value pairs, and we can swap the key and value just like swapping two normal variables. In this tutorial, we will learn different approaches to swapping all the key-values of JSON elements using JavaScript. Using the for...in Loop We can iterate through the keys of the JSON object using a for...in loop. After that, we can access the value from the object using the key and swap every key-value pair in the object. We need to ...
Read MoreHow to create every combination possible for the contents of two arrays in JavaScript
Creating every possible combination from two arrays is known as a Cartesian product. This involves pairing each element from the first array with every element from the second array. Problem Setup Given two arrays of literals: const arr1 = ["A", "B", "C"]; const arr2 = ["1", "2", "3"]; console.log("Array 1:", arr1); console.log("Array 2:", arr2); Array 1: [ 'A', 'B', 'C' ] Array 2: [ '1', '2', '3' ] We need to create all possible combinations by pairing each element from the first array with each element from the second array. ...
Read MoreSorting an array by price in JavaScript
Sorting an array of objects by price is a common requirement in JavaScript applications. This article demonstrates how to sort house data by price values stored as strings. Sample Data Let's start with an array of house objects where prices are stored as strings: const arr = [ { "h_id": "3", "city": "Dallas", "state": "TX", "zip": "75201", ...
Read MoreDifference between Python and JavaScript
JavaScript makes webpages interactive by working alongside HTML and CSS to improve functionality. It validates forms, creates interactive maps, and displays dynamic charts. When a webpage loads, the JavaScript engine in the browser executes the code after HTML and CSS have been downloaded, allowing real-time updates to the user interface. Modern JavaScript engines use just-in-time compilation, converting JavaScript code into bytecode for faster execution compared to traditional interpreters. Python is a general-purpose, high-level programming language created by Guido Van Rossum in 1989 and released in 1991. It's widely used for web development, machine learning, and software development, making ...
Read MoreSeparating digits of a number in JavaScript
In JavaScript, separating digits of a number is a common programming task. This tutorial shows how to extract and display each digit of a number individually using different approaches. Problem Statement We need to create a program that takes a number as input and displays each digit separately. For example, if the input is 43354, the output should be: 4 3 3 5 4 Method 1: Using Mathematical Operations This approach uses the modulo operator (%) and integer division to extract digits from right to left: ...
Read MoreSort by index of an array in JavaScript
Sorting an array of objects by a specific property is a common task in JavaScript. This tutorial demonstrates how to sort objects by their index property and extract specific values. Problem Statement Suppose we have the following array of objects: const arr = [ { 'name': 'd', 'index': 3 }, { 'name': 'c', ...
Read MoreHow to trim a file extension from a string using JavaScript?
Many web applications allow users to upload files and display filenames without extensions. Sometimes we need to store file content in databases using the filename without extension as a key. Here, we'll learn multiple ways to trim file extensions from strings using JavaScript. Using split(), pop() and join() Methods Every filename contains a file extension after the last dot. We can split the filename using '.' as a delimiter, remove the last element with pop(), and join the remaining parts back together. Syntax let split = fileName.split('.'); split.pop(); let finalName = split.join("."); Example ...
Read MoreGet the total number of same objects in JavaScript
When working with arrays of objects in JavaScript, you often need to count how many objects share the same property values. This is useful for analyzing data like flight routes, user preferences, or categorizing items. Suppose we have an array of objects describing flight routes: const routes = [ { flyFrom: "CDG", flyTo: "DUB", return: 0, }, { ...
Read More