Check a String Sontains a Substring in JavaScript? [Two Methods]

To check if a string contains a specific substring in JavaScript, you can use the includes() method or the indexOf() method. Here’s how you can use each method: Using includes() method: var str = “Hello, World!”; var substring = “Hello”; if (str.includes(substring)) { console.log(“Substring found!”); } else { console.log(“Substring not found.”); } In this example, … Read more

Javascript Substring vs Slice

Javascript Substring vs Slice

In JavaScript, both the substring() and slice() methods are used to extract portions of a string. While they have similar functionality, there are a few differences between them: Here are examples of using both methods to extract substrings: var str = “Hello, World!”; var substring = str.substring(0, 5); console.log(substring); // Output: Hello var sliced = … Read more

Remove Last Character | Javascript Substring [Easy Method]

Remove Last Character

To remove the last character from a string using JavaScript’s substring() method, you can specify the desired range of characters to extract. Here’s an example: var str = “Hello, World!”; var substring = str.substring(0, str.length – 1); console.log(substring); // Output: Hello, World In the above code, str.length – 1 is used as the endIndex parameter … Read more

What is Javascript Substring?

Javascript Substring

In JavaScript, the substring() method is used to extract a portion of a string based on specified starting and ending indexes. It returns the extracted substring as a new string. The syntax for the substring() method is as follows: string.substring(startIndex, endIndex) Here’s a breakdown of the parameters: Here’s an example to illustrate the usage of … Read more

Create async function in javascript

Certainly! Here’s an example of creating an asynchronous function in JavaScript using the async and await keywords: javascriptCopy code// Define an async function async function fetchData() { try { // Simulate an asynchronous operation, such as fetching data from an API const response = await fetch(‘’); const data = await response.json(); // Process the retrieved … Read more

How to make post request in Javascript?

To make a POST request in JavaScript, you can use the fetch() function or the XMLHttpRequest object. I’ll provide examples for both approaches: Using fetch(): javascriptCopy code// Create a JSON object with the data to be sent in the request body var data = { username: “john_doe”, password: “secretpassword” }; // Make a POST request … Read more

How to create a map in Javascript?

To create a map (also known as an object) in JavaScript, you can use curly braces {} to define and initialize it. Here’s an example: javascriptCopy code// Create an empty map var myMap = {}; // Add key-value pairs to the map myMap[“key1”] = “value1”; myMap[“key2”] = “value2”; myMap[“key3”] = “value3”; // Access values by … Read more

How to make a password generator in javascript?

To create a password generator in JavaScript, you can follow these steps: javascriptCopy codefunction generatePassword(length) { // Implement password generation logic here } javascriptCopy codevar uppercaseChars = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; var lowercaseChars = “abcdefghijklmnopqrstuvwxyz”; var numberChars = “0123456789”; var specialChars = “!@#$%^&*()_+~`|}{[]:;?><,./-=”; javascriptCopy codevar allChars = uppercaseChars + lowercaseChars + numberChars + specialChars; javascriptCopy codevar password = … Read more

10 Digit Mobile Number Validation in Jquery

To validate a 10 digit mobile number in jQuery, you can use regular expressions. Here’s an example code snippet to achieve this. HTML Form Jquery Code In the above code, replace “form-id” with the ID of your form, and “mobile-number-field” with the ID of the mobile number input field in your form. The regular expression … Read more

Random Color Generator In Javascript

Here’s a code for a random color picker in JavaScript: HTML code CSS Code Javascript Code This code generates a random hexadecimal color code and sets it as the background color of the webpage. BrijBrijpal Sharma is a web developer with a passion for writing tech tutorials. Learn JavaScript and other web development technology.