Found 8591 Articles for Front End Technology

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

392 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

353 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

305 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

How to get substring between two similar characters in JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 17:32:09

4K+ Views

Before we are going to learn about how to get substring between two similar characters in JavaScript. Let’s have a quick view on the characters in JavaScript. In a string, the charAt() method returns the character that is located at the given index (position). First character's index is 0, second character's index is 1. Getting substring in JavaScript The substring() method takes a string and extracts all characters between two indices (positions), then it returns the substring. Characters are taken out of a string using the substring() technique. The initial string is left alone when using the substring() technique. Syntax ... Read More

Capitalize a word and replace spaces with underscore - JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 16:58:12

2K+ Views

We will try to develop a method to change text with spaces and lowercase letters into text with underscores, where the initial letter of each word is capitalized. Let's examine the equation in its entirety. tutorials point = Tutorials_Point //expected output Let’s dive into article for getting better understanding on capitalize a word and replace spaces with underscore JavaScript. Using replace() method The replace() method looks up a value or regular expression in a string. A new string with the replaced value() is the result of the replace() method. The original string is unchanged by the replace() technique. Syntax ... Read More

How to replace all the special characters following another character – JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 16:45:58

1K+ Views

Characters that are neither alphabetical nor numeric are known as special characters. Special characters are essentially all unreadable characters, including punctuation, accent, and symbol marks. Remove any special characters from the string to make it easier to read and understand. We use replace() method to replace all the special characters following another character. Using replace() method The JavaScript built-in method string.replace() can be used to replace a portion of a supplied string with another string or a regular expression. The original string won't alter at all. Syntax Following is the syntax for replace() − string.replace(searchValue, newValue) Let’s look into ... Read More

Advertisements