Nikhilesh Aleti

Nikhilesh Aleti

69 Articles Published

Articles by Nikhilesh Aleti

Page 3 of 7

Reorder an array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 10K+ Views

Reordering an array means changing the sequence of elements within the array. JavaScript provides several built-in methods to reorder arrays, each serving different purposes. Using sort() for Alphabetical Ordering The sort() method sorts array elements alphabetically in ascending order by default. It modifies the original array. const states = ["Telangana", "Uttar Pradesh", "Karnataka", "Kerala", "TamilNadu"]; document.getElementById("para1").innerHTML = "Original: " + states; states.sort(); ...

Read More

Decimal count of a Number in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 14K+ Views

Given there is a number with digits after decimal point and the task is to find the count of digits after the decimal point. Input Output Scenario Let's look into the input output scenario, where there is a floating point number having some digits after decimal point. Input = 45.36346323 Output = 8 As we can see in the above snippet there are 8 digits in the floating point number after the decimal point. To achieve this task, we'll explore three different methods using isInteger(), toString(), and split() methods. Method 1: Using ...

Read More

Converting two arrays into a JSON object in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 5K+ Views

Given two arrays and the task is to convert those two arrays into a JSON object. Where the first array elements are keys of the object and the second array elements are values of the object. Input-Output Scenario Let's look into the scenario of how two arrays will be converted into a JSON object. Consider two arrays are having some elements. Now, we need to convert these two arrays into a JSON object. Array1 = [1, 2, 3, 4]; Array2 = ['A', 'B', 'C', 'D']; Output = {"1":"A", "2":"B", "3":"C", "4":"D"} //JSON object ...

Read More

Removing property from a JSON object in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 7K+ Views

A JSON (JavaScript Object Notation) object is a data structure surrounded by curly braces {}. JSON objects contain key-value pairs where keys must be strings and values can be numbers, strings, objects, booleans, arrays, or null. JavaScript provides several methods to remove properties from objects. Each method has different characteristics - some modify the original object, while others create new objects without the unwanted properties. Basic JSON Object Structure Here's the basic syntax for a JSON object: const jsonObject = { "name": "John", "age": 30, "city": ...

Read More

Best way to find length of JSON object in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 17K+ Views

In JavaScript, objects don't have a built-in length property like arrays. However, there are several reliable methods to find the number of properties in a JSON object. Input-Output Scenario Consider an object with some keys and values. We need to get the count of its properties: const MyObj = { Name: "Mike", Age: 34 }; console.log(Object.keys(MyObj).length); // Output: 2 Using Object.keys() (Recommended) The Object.keys() method returns an array of a given object's own enumerable property names. It returns the keys in the same order as they ...

Read More

Sort array of objects by string property value in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

The given task is to sort an array of objects by using string property value in JavaScript. Assume there is an array of objects and we need to sort those elements by using the string property. In this below scenario, we are sorting array of objects by "Company" property. const array = [ {Company: 'Oneplus', Manufacturing: 'China'}, {Company: 'Samsung', Manufacturing: 'South korea'}, {Company: 'Nothing', Manufacturing: 'India'} ]; // Output after sorting by "Company" property: [ {"Company":"Nothing", "Manufacturing":"India"}, {"Company":"Oneplus", "Manufacturing":"China"}, ...

Read More

Removing Negatives from Array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 2K+ Views

In JavaScript, you often need to remove negative values from an array. This article shows three effective methods to accomplish this task. Input-Output Scenarios Let's look at typical scenarios. When an array contains both negative and positive values, we need to filter out the negatives: Input = [-2, 5, -7, 32, 78, -32] Output = [5, 32, 78] If the array contains only positive values, it remains unchanged: Input = [56, 43, 12, 67, 69, 34] Output = [56, 43, 12, 67, 69, 34] Using the filter() Method (Recommended) ...

Read More

Join arrays to form string in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 456 Views

JavaScript provides built-in methods to join array elements into strings. The join() method converts a single array to string, while concat() combined with join() handles multiple arrays. Input-Output Scenarios Converting a single array to string: Input = [32, 45, 65, 12, 07, 55]; Output = "32, 45, 65, 12, 7, 55" // String Joining multiple arrays into a single string: Array1 = [123, 453, 656, 654, 125, 757]; Array2 = ["Hello", "honey", "bunny"]; Output = "123, 453, 656, 654, 125, 757, Hello, honey, bunny" // String Using Array.join() Method ...

Read More

How to replace elements in array with elements of another array in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 7K+ Views

In JavaScript, there are several ways to replace elements in one array with elements from another array. The most common approach uses the splice() method to modify the original array in place. Input-Output Scenarios Let's look at some common scenarios for replacing array elements: Array1 = [1, 3, 5, 7, 2, 4]; Array2 = [3, 6]; // Replace first 2 elements of Array1 with Array2 Output = [3, 6, 5, 7, 2, 4] Array1 = [3, 6]; Array2 = [1, 3, 5, 7, 2, 4]; // Replace all elements of Array1 with Array2 ...

Read More

Recursion example in JavaScript to display numbers is descending order?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 1K+ Views

In this article, we will display numbers in descending order using recursion in JavaScript. Recursion is a programming technique where a function calls itself to solve smaller instances of the same problem. Input-Output Scenario Let's look at an input-output scenario where we need to print numbers in descending order from a given number to 1: Input = 10 Output = 10 9 8 7 6 5 4 3 2 1 What is Recursion? The process of a function calling itself is called recursion. The function which calls itself is known as a recursive ...

Read More
Showing 21–30 of 69 articles
« Prev 1 2 3 4 5 7 Next »
Advertisements