Found 6710 Articles for Javascript

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

Generate random string/characters in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 17:27:30

5K+ Views

Scripting in JavaScript is simple, cross-platform, and lightweight. It is widely used in nonbrowser situations and is well known for web page building. Both client-side and serverside development can be done with JavaScript. JavaScript has built-in methods that can be used to generate random strings and modify the Document Object Model (DOM) in accordance with our needs. The random() function, which helps to generate the random index and multiple with the length of the string, will be accessed through the Math library. It will append the character from the string or character set as it is passed. Create ... Read More

How to filter an array from all elements of another array – JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 17:25:53

587 Views

The task we are going to perform in this article is how to filter an array from all elements of another array JavaScript. Before we dive into the article, let’s have a quick view on the array in JavaScript. When storing multiple values in a single variable, arrays are used. When compared 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. In ... Read More

Using JSON.stringify() to display spread operator result?

AmitDiwan
Updated on 09-Nov-2020 07:46:10

1K+ Views

With Spread Operator, allow the expression to expand to multiple arguments, elements, variables, etc.You can use JSON.stringify() to convert the JavaScript object to string. Here, we have our object as the result of using spread operator on details1 and details2.ExampleFollowing is the code −var details1 = { name: 'John', age: 21 }; var details2 = { countryName: 'US', subjectName:'JavaScript' }; var result= { ...details1, ...details2}; console.log(JSON.stringify(result));To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo267.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo267.js {"name":"John", "age":21, "countryName":"US", "subjectName":"JavaScript"}Read More

How to test if a URL string is absolute or relative - JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 17:24:21

2K+ Views

Knowing whether or not a user has entered an absolute or relative path in your application allows you to make decisions regarding where content should be pulled from, and how certain actions should be handled. In this article, we'll go over how to use JavaScript to quickly and easily determine if a given URL string is absolute or relative. Absolute Url is a URL that includes all the data necessary for finding the resources. The protocol (HTTPS) in the site's domain at the beginning of the URL is the element that is included in the absolute URL. Following is the ... Read More

How to open link in a new window using JavaScript?

Yaswanth Varma
Updated on 25-Sep-2024 15:30:18

9K+ Views

If you want users to click on links and open those links in a new window becouse you want your user to stay on your site while they view the linked content. Then you need to use this solution. By using JavaScript you can easily configure all of your links so that they open in a new window when clicked. Approach to Open Link in a New Window Using window.open() Method Using window.open() Method JavaScript window.open() method allows you to open a new browser window or tab, with the specified URL. ... Read More

How to fetch character from Unicode number - JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 17:18:45

3K+ Views

In this article we are going to learn about how to fetch character from Unicode number JavaScript. Before we jump into the article let’s have a quick view on the Unicode number in JavaScript. A Unicode escape sequence in JavaScript can be used to express identifiers and string literals in Unicode. A four-digit hexadecimal value for X indicates the basic syntax, which is uXXXX. Let’s dive into the article to learn more about “How to fetch character from Unicode number JavaScript.” To retrieve character from Unicode number, use String.fromCharCode() in JavaScript String.fromCharCode() method in JavaScript The JavaScript string method charCodeAt() ... Read More

Accessing and returning nested array value - JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 16:33:16

2K+ Views

Each value in an array is referred to as an element, and each element has a certain numerical location in the array, which is referred to as its index. Nested Arrays, a feature of JavaScript, allow us to create arrays inside arrays. One or more arrays can be used as the elements of nested arrays. Although the term may be a little unclear, as we look further, it is actually rather fascinating. Accessing and returning nested array In JavaScript, a nested array is described as an Array (Outer array) inside another array (inner array). One or more inner Arrays are ... Read More

Advertisements