
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

4K+ Views
Let’s say we have the following sample video tag on a web page You cannot play video here...... To hide a video on a web page, use yourVariableName.style.display=’none’.ExampleFollowing is the code − Document .hideVideo { display: block; z-index: 999; margin-top: 10px; margin-left: 10px; } You cannot play video here...... var hideVideo = document.getElementsByClassName("hideVideo")[0]; hideVideo.style.display = ... Read More

2K+ Views
The task we are going to perform in this article is make strings in array become keys in object in a new array in JavaScript. Let’s consider a simple array − let array= ['bike', 'car'] Now, we are going to use map() to convert the above array to a new array (keys in an object). The array will then look like this − let newArray= [{shorts: []}, {tees: []}, ] Let’s dive into the article to learn more about on making a strings in array become keys in object in a new array in JavaScript. Using map() The ... Read More

906 Views
Let’s say the following is our unsorted array with negative and positive numbers −var arr = [10, -22, 54, 3, 4, 45, 6];ExampleFollowing is the code to implement Bubble Sort −function bubbleSort(numberArray, size) { for (var lastIndex = size - 1; lastIndex > 0; lastIndex--) { for (var i = 0; i < lastIndex; i++) { if (numberArray[i] > numberArray[i + 1]) { var temp = numberArray[i]; numberArray[i] = numberArray[i + 1]; numberArray[i + ... Read More

1K+ Views
An array is an ordered list of values in JavaScript. The term "element designated by an index" refers to each value: The following traits describe a JavaScript array: An array can initially store values of many sorts. You could, for instance, store elements of the number, string, Boolean, and null types in an array. Let’s jump into the article to detect and replace all the array elements in a string using regexp in JavaScript. Using regexp in JavaScript A regular expression is a character pattern. Pattern-matching "search-and-replace" operations are performed on text using the pattern. A RegExp Object is a ... Read More

391 Views
To substitute random items with items from an array with different ones in JavaScript. Let’s look at the instance; the array is − Var array=[m, n, o, p] Let's choose two random items to be replaced with a, while the others remain in their original positions. If m and n are the randomly selected items, and one is removed on one instance, the array would be − Changed array=[a, a, o, p] Let’s dive into the article to learn more about substituting random items in a JavaScript array. To substitute random items, use random() along with map(). Using ... Read More

352 Views
Let’s say the following is our array object −var arrayObject = [ "John", "David", "Mike" ]You can use length property to set the length to 0 and clear memoryThe syntax is as follows to clear memory −yourArrayObjectName.length=0; // To clear memory yourArrayObjectName.length=4; // To allocate memoryOutputThis will produce the following output on console −var arrayObject = [ "John", "David", "Mike" ] arrayObject.length = 0; console.log(arrayObject); arrayObject.length = 5; for (var i = 0; i < arrayObject.length; i++) ... Read More

3K+ Views
The most practical way to display datetime for efficient time analysis is in a 12 hour am/pm format. Additionally, this method clarifies the distinction between morning and evening. As an illustration, "am/pm" both specify a certain time period and make it simple to understand the time, which is not the case with the 24-hour format. This article will explain the ways of displaying JavaScript datetime in 12hour am/pm format. Displaying JavaScript datetime in 12hour am/pm format Let’s dive one by one to understand more about displaying JavaScript datetime in 12hoyur am/pm format. We can extract the hours and minutes from ... Read More

1K+ Views
You can use event listeners for clicks.ExampleFollowing is the code − Live Demo Document First Division Second Division document.addEventListener('click', callEventFuncion) function callEventFuncion(event) { var div = document.querySelectorAll('.divDemo'); var titleResult = document.querySelectorAll('.my-title'); var result = Array.apply(0, div).find((v) => v.contains(event.target)); if (result) { console.log(" Incrementing Division Selection"); } else { ... Read More

3K+ Views
In JavaScript Arrays are used to hold several values in a single variable. When opposed to a variable, which can hold only one value, this Each element of an array has a number associated with it called a numeric index that enables access to it. Arrays in JavaScript begin at index zero and can be modified using a number of different techniques. Let's take a look at the general case of sorting an array that contains undefined in JavaScript. The array is given below − var namearr = ["Zebra", "Yatch", undefined, "Egg", undefined]; For sorting the array that was ... Read More

304 Views
For this, use join(). It will concatenate the string value length-1.ExampleFollowing is the code −var count = 5; var values = new Array(count + 1).join('John'); console.log(values); var count1 = 5; var values1 = new Array(count1).join('John'); console.log(values1);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo274.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo274.js JohnJohnJohnJohnJohn JohnJohnJohnJohn