Found 6710 Articles for Javascript

Hide a video tag on a web page - JavaScript

AmitDiwan
Updated on 09-Nov-2020 08:18:01

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

Make strings in array become keys in object in a new array in JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 17:23:05

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

Implement Bubble sort with negative and positive numbers – JavaScript?

AmitDiwan
Updated on 09-Nov-2020 08:13:49

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

How to detect and replace all the array elements in a string using RegExp in JavaScript? 

Yaswanth Varma
Updated on 21-Apr-2023 17:24:34

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

Substitute random items in a JavaScript array?

Yaswanth Varma
Updated on 21-Apr-2023 17:26:42

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

What happens when length of object is set to 0 - JavaScript?

AmitDiwan
Updated on 09-Nov-2020 08:07:12

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

How do you display JavaScript datetime in 12hour AM/PM format?

Yaswanth Varma
Updated on 21-Apr-2023 17:28:47

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

How to make a condition for event 'click' inside/outside for multiple divs - JavaScript?

AmitDiwan
Updated on 09-Nov-2020 08:02:07

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

Sorting an array that contains undefined in JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 17:30:37

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

How to concatenate the string value length -1 in JavaScript.

AmitDiwan
Updated on 09-Nov-2020 07:54:56

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

Advertisements