- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6686 Articles for Javascript
![Nikhilesh Aleti](https://www.tutorialspoint.com/assets/profiles/519798/profile/60_1221559-1663324574.jpg)
247 Views
In this article, the given task is to check the equality of array elements (sequence dependent). Before we proceed into examples, let’s look at how the input-output scenario will look when we are checking the equality of array elements (sequence dependent) in JavaScript. Input-Output scenario Let’s look into the input-output scenario, where we have declared two arrays and we need to get similar elements in sequence-dependent. Array1 = [2, 5, 6, 7, 9, 0]; Array2 = [3, 5, 0, 8, 9, 4]; Output = [5, 9] In the above snippet, we can see that there are two arrays ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
6K+ Views
We have a special kind of string that contains characters in couple, like this −const str = "AABBCCDDEE";We are required to construct an object based on this string which should look like this −const obj = { code: "AA", sub: { code: "BB", sub: { code: "CC", sub: { code: "DD", sub: { code: "EE", sub: {} ... Read More
![Nikhilesh Aleti](https://www.tutorialspoint.com/assets/profiles/519798/profile/60_1221559-1663324574.jpg)
12K+ Views
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 will start form 0. Syntax Following is the syntax of the array in JavaScript – const array_name = [item1, item2, ...]; The following is the simple declaration of array in JavaScript, Const colors = ['Blue', 'Limegreen', 'Orange', 'Black']; Let’s assume some simple ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
240 Views
We have to write a function that takes in an array, removes all duplicates from it and inserts the same number of empty strings at the end.For example:If we find 4 duplicate values we have to remove then all and insert four empty strings at the end.Therefore, let’s write the code for this function −ExampleThe code for this will be −const arr = [1, 2, 3, 1, 2, 3, 2, 2, 3, 4, 5, 5, 12, 1, 23, 4, 1]; const deleteAndInsert = arr => { const creds = arr.reduce((acc, val, ind, array) => { let ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
79 Views
We have to write a simple function in JavaScript that takes in an array of Numbers (nested to any level) and return the greatest number present in the array.For example:If the input array is −const arr = [ 34, 65, 67, [ 43, 76, 87, 23, 56, 7, [ 54, 7, 87, 23, 79, 994, 2 ], 54 ], 54, 4, 2 ];Then the output should be −994We will use recursion to find the greatest number in the array, Therefore, let’s ... Read More
![Nikhilesh Aleti](https://www.tutorialspoint.com/assets/profiles/519798/profile/60_1221559-1663324574.jpg)
2K+ Views
Given a multidimensional array and the task is to pick the largest elements from it in JavaScript. The multidimensional arrays are an arrays inside an array. whenever there are arrays inside the array it will work as multidimensional array. Following is the one-dimensional array - const arr = ["Welcome", "to", "tutorials", "point"]; const arr = [1, 5, 12, 67, 99]; This is how the multidimensional array look like - const array=[["Mike tyson", "Vijay"], ["ananya", "charmee"], ["Lion", "Tiger"]]; This is how we can access the elements from multidimensional array - const array = [["Mike tyson", "Vijay"], ["ananya", ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
145 Views
We have an array of numbers and are required to write a function that returns an array with the average of the corresponding element and its predecessor.For the first element, as there are no predecessors, so that very element should be returned.Let’s write the code for this function, we will use the Array.prototype.map() function to solve this problem.ExampleThe code for this will be −const arr = [3, 5, 7, 8, 3, 5, 7, 4, 2, 8, 4, 2, 1]; const consecutiveAverage = arr => { return arr.map((el, ind, array) => { const first = (array[ind-1] || ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
337 Views
We have to write a function that takes in an array, removes all duplicates from it and inserts the same number of empty strings at the end.For example: If we find 4 duplicate values we have to remove then all and insert four empty strings at the end.Therefore, let’s write the code for this function −ExampleThe code for this will be −const arr = [1, 2, 3, 1, 2, 3, 2, 2, 3, 4, 5, 5, 12, 1, 23, 4, 1]; const deleteAndInsert = arr => { const creds = arr.reduce((acc, val, ind, array) => { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
158 Views
We have to write a simple function in JavaScript that takes in an array of Numbers (nested to any level) and return the greatest number present in the array.For example: If the input array is −const arr = [ 34, 65, 67, [ 43, 76, 87, 23, 56, 7, [ 54, 7, 87, 23, 79, 994, 2 ], 54 ], 54, 4, 2 ];Then the output should be −994We will use recursion to find the greatest number in the array.ExampleThe code ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
108 Views
We are required to write a function that returns the index of the very first element that appears at least twice in the array. If no element appears more than once, we have to return -1. We have to do this in constant space (i.e., without utilizing extra memory).So, let's write the solution for this problem.We will use a for loop to iterate over the array and use the Array.prototype.lastIndexOf() method to check for duplicacy.ExampleThe code for this will be −const arr1 = [0, 1, 1, 2, 3, 4, 4, 5]; const firstRedundant = arr => { for(let i ... Read More