
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 6710 Articles for Javascript

309 Views
In this article, we are going to discuss the importance of iterator functions in JavaScript. We can use the iterator function to iterate over an array. Other than Explicit iteration, Javascript provides a variety of iteration functions that you can use to iterate over arrays. Here, we use the forEach(), the filter method(), and the map() method to iterate over the arrays and perform the required operations. ForEach Function This function takes a function as a parameter and executes it as you pass to it for every object in the array.Syntax Following is the syntax of the forEach() method. array.forEach(function(currentValue, ... Read More

336 Views
The do...while loop is similar to the while loop except that the condition check happens at the end of the loop. This means that the loop will always be executed at least once, even if the condition is false.For example,Examplelet i = 0; do { console.log("Hello"); i = i + 1; } while (i < 5);This will give the output −OutputHello Hello Hello Hello Hello

328 Views
Basically, multi-dimension arrays are used if you want to put arrays inside an array. Let's take an example. Say you wanted to store every 6 hour's temperature for every weekday. You could do something like −let monday = [35, 28, 29, 31]; let tuesday = [33, 24, 25, 29]; //...This is a good place to use a multidimensional array instead. A multidimensional array is nothing but an array of arrays. If we take forward our example, each row will represent a day while each entry in the row will represent a temp entry. For example, let temps = [ ... Read More

536 Views
Javascript provides a collection of functions that you can use to find elements in an array. Let's start with the most basic one. The indexOf function goes through the entire array and returns the index of the element you searched for, if it is found else it returns -1. For example, Examplelet people = ["Harry", "Martha", "John", "Sam"]; console.log(people.indexOf("John")) console.log(people.indexOf("Jim"))OutputThis will give the output −2 -1There are other, more complex functions that you can use to make search more powerful. Let's look at find() method. The find() method returns the first object matching the condition you provide it as the ... Read More

272 Views
There are two ways to join 2 arrays in Javascript. If you want to get a new array and not want to disturb the existing arrays while joining the two arrays then you should use the concat method as follows − Examplelet arr1 = [1, 2, 3, 4]; let arr2 = [5, 6, 7, 8]; let arr3 = arr1.concat(arr2); console.log(arr1); console.log(arr2); console.log(arr3);OutputThis will give the output −[1, 2, 3, 4] [5, 6, 7, 8] [1, 2, 3, 4, 5, 6, 7, 8]Note that the existing arrays were not modified. If you want to join in place, you'll need to use the ... Read More

308 Views
In this article, we are going to discuss removing an element from a given position of the array in JavaScript. The delete operator, the slice() method, and the splice() method can be used to remove an element from a given position of the array in this article. Following is the syntax of the delete operator. let del = delete arr[index]; Following is the syntax of the slice() method. arr.slice(start, end) Following is the syntax of the splice() method. arr.splice(position, no_of_elem) Using delete Operator Example In this example, we are going to discuss the use of the ... Read More

167 Views
In this article, we are going to discuss removing an element from the start of the array in JavaScript. For that, we are going to use the _.rest() method. This method returns the array elements except for the 0th indexed element. We can also use the shift() method and the slice() method to remove the first element from an array. Let us see the implementation of it further. Using _.rest() Method The following example demonstrates how to remove the start element from an array in JavaScript. Syntax The syntax of the _.rest() method is − _.rest( array, index ); ... Read More

267 Views
In this article, we are going to discuss how to remove an element from the end of the array in JavaScript. An array is a special variable, which can hold more than one value. An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items together. This makes it easier to calculate the position of each element by simply adding an offset to a base value of the memory location of the first element of the array. The base value is index 0 for the first element in the array and the ... Read More

370 Views
In this article, we are going to learn how to add an element at the start of the array in JavaScript. An array is a special variable, which can hold more than one value sequentially. It is a collection of items stored at contiguous memory locations. The idea is to store multiple items together. This makes it easier to calculate the position of each element by simply adding an offset to a base value of the memory location of the first element of the array. The base value is index 0 for the first element in the array and the ... Read More

513 Views
In this article, we are going to add an at the end of the array in JavaScript. An array is a special variable, which can hold more than one value. An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items together. This makes it easier to calculate the position of each element by simply adding an offset to a base value of the memory location of the first element of the array. The base value is index 0 for the first element in the array and the difference between the two ... Read More