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 by Nikhilesh Aleti
Page 3 of 7
Finding the mid of an array in JavaScript
Finding the middle element of an array is a common programming task in JavaScript. The approach differs depending on whether the array has an odd or even number of elements. Array Basics An Array in JavaScript is a data structure used to store multiple elements. These elements are stored at contiguous memory locations and accessed using index numbers starting from 0. Syntax const array_name = [item1, item2, ...]; Example of array declaration: const body = ['Eyes', 'Nose', 'Lips', 'Ears']; Understanding Middle Element Logic Finding the middle element depends ...
Read MoreFinding product of Number digits in JavaScript
We are required to write a JavaScript program that takes in a number and finds the product of all of its digits. Input Output Scenarios Here are examples of finding the product of number digits: Input = 12345 Output = 120 (1 × 2 × 3 × 4 × 5 = 120) We can also work with string numbers and convert them to integers: Input = "12345" Output = 120 Using Math.floor() and Modulo Operator The Math.floor() function returns the largest integer less than or equal to a given ...
Read MorePicking the largest elements from multidimensional array in JavaScript
Given a multidimensional array, we need to pick the largest elements from each subarray in JavaScript. The multidimensional arrays are arrays inside an array. Whenever there are arrays inside the array, it works as a multidimensional array. Following is a one-dimensional array: const arr = ["Welcome", "to", "tutorials", "point"]; const numbers = [1, 5, 12, 67, 99]; This is how a multidimensional array looks like: const array = [["Mike tyson", "Vijay"], ["ananya", "charmee"], ["Lion", "Tiger"]]; This is how we can access elements from a multidimensional array: ...
Read MoreFilter array based on another array in JavaScript
In this article, we are going to learn how to filter an array based on another array in JavaScript. An Array in JavaScript is used to store different elements. These elements are stored at contiguous memory locations. By using index numbers, we can access any or each data element present in the array. Index numbers start from 0. Syntax Following is the syntax of the array in JavaScript – const array_name = [item1, item2, ...]; The following is a simple declaration of array in JavaScript: const colors = ['Blue', 'Limegreen', 'Orange', ...
Read MoreChecking the equality of array elements (sequence dependent) in JavaScript
In this article, we'll learn how to check the equality of array elements in a sequence-dependent manner. This means comparing arrays element by element at the same index positions to find matching values or count similarities. Input-Output Scenario Let's look at how sequence-dependent comparison works with two arrays: Array1 = [2, 5, 6, 7, 9, 0]; Array2 = [3, 5, 0, 8, 9, 4]; Output = [5, 9] In the above example, elements 5 and 9 appear at the same index positions (index 1 and 4) in both arrays, making them sequence-dependent matches. ...
Read MoreHow to clone an array using spread operator in JavaScript?
In this article, we are going to discuss how to use the spread operator to clone an array in JavaScript. Cloning is the process of copying one array into another array. Previously, the slice() method was used to clone an array, however, ES6 now provides the spread operator (...) to simply clone an array. What is Array Cloning? An Array is a data structure in JavaScript that can hold multiple values at once. Cloning involves copying an array's elements to create a new independent array. ...
Read MoreLooping through an array in Javascript
Arrays are linear data structures that store multiple elements in an ordered collection. Each element can be accessed using its index number, starting from 0. const array_name = [item1, item2, ...]; const movies = ["Bahubali", "RRR", "KGF", "Pushpa"]; // Index values: // Bahubali – [0] // RRR – [1] // KGF – [2] // Pushpa – [3] Loops are programming constructs that execute a sequence of instructions repeatedly until a specified condition is met. They're essential for iterating through arrays efficiently. Traditional for Loop The for loop provides complete control over initialization, condition, ...
Read MoreHow to compare two objects in JavaScript?
Objects in JavaScript are entities that consist of properties and types. For example, a car object might have properties like color, price, height, and width. const car = { color: 'Black', price: 2500000, height: '6 feet', width: '5 feet' } The equality operator (===) verifies whether two operands are equal and returns a Boolean value. However, it cannot directly compare objects because objects are reference types. document.write('tutorix' === 'tutorix' ...
Read MoreHow to Split large string in to n-size chunks in JavaScript?
A string is an order of one or more characters that contain numbers, letters, symbols, or special characters. In JavaScript strings are immutable. i.e., once you create a string you cannot change its value. For example, consider the following snippet here we have created a string variable and assigned a value (Tutorialspoint) to it. In the next statement, we are trying to change the contents of the string at the first index. Then we are displaying the contents of the string. let x = 'Tutorialspoint'; x[0] = 't'; console.log(x); // Tutorialspoint ...
Read MoreHow to convert a string to a floating point number in JavaScript?
In JavaScript, converting a string to a floating point number is a common task that can be accomplished through several methods. This article explores three effective approaches to achieve this conversion. Using the parseFloat() Method The parseFloat() function is the most direct way to convert a string to a floating point number. It parses a string and returns the first number found, including decimal values. Syntax parseFloat(string) Note: If the first character cannot be converted to a number, parseFloat() returns NaN. Example: Basic parseFloat() Usage ...
Read More