Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Javascript Articles
Page 448 of 534
How do you launch the JavaScript debugger in Google Chrome?
To launch JavaScript debugger in Google Chrome, try any of the following ways,Press Ctrl + Shift + JGo to Settings and click More Tools. After that, click Developer Tools.For more, refer the official website of Chrome Dev Tool,
Read MoreHow to define custom JavaScript exceptions?
To learn how to define and implement custom JavaScript exceptions, you can try to run the following code −Example Click the following to see the result:
Read MoreWhat is the difference between custom and built-in functions in JavaScript?
The custom functions in JavaScript are user-defined functions. JavaScript allows us to write our own functions. The following is the syntax −Syntax Bult-in functions are functions already provided by JavaScript library, for example, the following are string functions −S. NoMethod & Description1charAt()Returns the character at the specified index.2charCodeAt()Returns a number indicating the Unicode value of the character at the given index.3concat()Combines the text of two strings and returns a new string.4indexOf()Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found.ExampleThe following is an example of a built-in ...
Read MoreHow to write a Regular Expression in JavaScript to remove spaces?
To remove spaces in JavaScript, you can try to run the following regular expression. It removes the spaces from a string −Example Live Demo var str = "Welcome to Tutorialspoint"; document.write(str); //Removing Spaces document.write(""+str.replace(/\s/g, '')); Output
Read MoreHow to write JavaScript Regular Expression for multiple matches?
To find multiple matches, write a JavaScript regular expression. You can try to run the following code to implement regular expression for multiple matches −Example var url = 'https://www.example.com/new.html?ui=7&demo=one&demo=two&demo=three four', a = document.createElement('a'); a.href = url; var demoRegex = /(?:^|[&;])demo=([^&;]+)/g, matches, demo = []; while (matches = demoRegex.exec(a.search)) { demo.push(decodeURIComponent(matches[1])); } document.write(demo);
Read MoreWrite a Regular Expression to remove all special characters from a JavaScript String?
To remove all special characters from a JavaScript string, you can try to run the following code −Example var str = "@!Welcome to our website$$"; document.write(str); // Removing Special Characters document.write(""+str.replace(/[^\w\s]/gi, ''));
Read MoreHow to skip character in capture group in JavaScript Regexp?
You cannot skip a character in a capture group. A match is always consecutive, even when it contains things like zero-width assertions.ExampleHowever, you can access the matched groups in a regular expression like the following code − var str = "Username akdg_amit"; var myReg = /(?:^|\s)akdg_(.*?)(?:\s|$)/g; var res = myReg.exec(str); document.write(res[1]);
Read MoreHow to set current time to some other time in JavaScript?
You cannot do this with JavaScript since it takes the system time which displays the current date with Date object. However, you can change the current date by changing the timezone as in the following code −Example Live Demo var date, offset, nd; date = new Date(); document.write("Current: "+date); utc = date.getTime() + (date.getTimezoneOffset() * 60000); // Singapore is GMT+8 offset = 8; nd = new Date(utc + (3600000*offset)); document.write("Singapore Time: "+nd.toLocaleString()); Output
Read MoreThe Fibonacci sequence in Javascript
Fibonacci numbers are the numbers such that every number in the series after the first two is the sum of the two preceding ones. The series starts with 1, 1. Example −1, 1, 2, 3, 5, 8, 13, 21, 34, ….We can write a program to generate nth as follows −functionfibNaive(n) { if (n
Read MoreHow to define a JavaScript function using Function() Constructor?
The Function() constructor expects any number of string arguments. The last argument is the body of the function - it can contain arbitrary JavaScript statements, separated from each other by semicolons.ExampleYou can try to run the following code to invoke a function with new Function Constructor − var func = new Function("x", "y", "return x*y;"); function multiplyFunction(){ var result; result = func(15,35); document.write ( result ); } Click the following button to call the function
Read More