- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6686 Articles for Javascript
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
986 Views
Let’s say the following is our value −var value="97%";To check the value for percentage, use regular expression.ExampleFollowing is the code −var value="97%"; var result=/^\d+(\.\d+)?%$/.test(value); if (result==true) { console.log("The percent is="+value); } else { console.log("This is not percentage"); } var value1="percent"; var result1=/^\d+(\.\d+)?%$/.test(value1); if (result1==true) { console.log("The percent is="+value1); } else { console.log("This is not percentage"); }To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo214.js.OutputThe output is as follows on console −PS C:\Users\Amit\JavaScript-code> node demo214.js The percent is=97% This is not percentageRead More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
To store large numbers in JavaScript, use BigInt() rather than + operator. If you will use the + operator, then expect loss of precision.Let’s say the following is our large number and we are storing using BigInt() −console.log("Loss of precision with + operator..")ExampleFollowing is the code −var stringValue1="100"; console.log("The integer value="); console.log(+stringValue1); var stringValue2="2312123211345545367"; console.log("Loss of precision with + operator..") console.log(+stringValue2); const storeLongInteger=BigInt("2312123211345545367"); console.log("No loss of precision with BigInt()"); console.log(storeLongInteger);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo212.js.OutputThe output is as follows on console −PS C:\Users\Amit\JavaScript-code> node demo213.js The ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
452 Views
To convert integer array to string array, use the map(String) in JavaScript. Let’s say the following is our integer array −var integerValues = [101, 50, 70, 90, 110, 90, 94, 68];Convert integer array to string array −integerValues.map(String);ExampleFollowing is the code −var integerValues = [101, 50, 70, 90, 110, 90, 94, 68]; console.log("The integer array value="); console.log(integerValues); integerValues.map(String); console.log("The string array value="); console.log(integerValues)To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo212.js.OutputThe output is as follows in console −PS C:\Users\Amit\JavaScript-code> node demo212.js The integer array value= [ 101, 50, 70, 90, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
24K+ Views
Let's say the following is our JSON string −var details = [ { customerName: "Chris", customerAge: 32 }, { customerName: "David", customerAge: 26 }, { customerName: "Bob", customerAge: 29 }, { customerName: "Carol", customerAge: 25 } ]To remove JSON element, use the delete keyword in JavaScript.ExampleFollowing is the complete code to remove JSON element −var details = [ { customerName: "Chris", ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
372 Views
Suppose we have an array that contains some dates like this −const arr = [ [ '02/13/2015', 0.096 ], [ '11/15/2013', 0.189 ], [ '05/15/2014', 0.11 ], [ '12/13/2013', 0.1285 ], [ '01/15/2013', 0.12 ], [ '01/15/2014', 0.11 ], [ '02/14/2014', 0.11 ], [ '03/14/2014', 0.11 ], [ '01/15/2015', 0.096 ], [ '07/15/2015', 0.096 ], [ '04/15/2013', 0.12 ], [ '04/15/2014', 0.11 ], [ '05/15/2013', 0.12 ], [ '06/14/2013', 0.12 ], [ '06/16/2014', 0.11 ], [ '07/15/2013', 0.12 ], [ '07/15/2014', 0.11 ], ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
378 Views
We are required to write a JavaScript function that takes in an array of strings and returns an object corresponding to the strings.For example −If the array is −const arr = [ "country.UK.level.1", "country.UK.level.2", "country.US.level.1", "country.UK.level.3" ];Then the output should be −const output = { "country": [ {"UK" : {"level" : ["1", "2", "3"]}}, {"US" : {"level" : ["1", "2"]}} ] } ConditionsStrings stored in the str array will not be sorted and the code should be robust against that.Strings will follow the x.y.x.y... pattern, where x will be ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
93 Views
We are required to write a JavaScript function that takes in an array of strings. The function should join all the strings of the array, replace all the whitespaces with dash "-", and return the string thus formed.For example: If the array is −const arr = ["QA testing promotion ", " Twitter ", "Facebook ", "Test"];Then the output should be −const output = "QA-testing-promotion-Twitter-Facebook-Test";ExampleFollowing is the code −const arr = ["QA testing promotion ", " Twitter ", "Facebook ", "Test"]; const joinArr = arr => { const arrStr = arr.join(''); let res = ''; for(let i = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
188 Views
Given an array X of multiple values (e.g. [-3, 5, 1, 3, 2, 10]), We are required to write a function that removes any negative values in the array.Once the function finishes its execution the array should be composed of just positive numbers. We are required to do this without creating a temporary array and only using pop method to remove any values in the array.ExampleFollowing is the code −// strip all negatives off the end while (x.length && x[x.length - 1] < 0) { x.pop(); } for (var i = x.length - 1; i >= 0; i--) { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
109 Views
Given an array of integers, we are required to write a function that takes this array and finds the one element that appears an odd number of times. There will always be only one integer that appears an odd number of times.We will approach this problem by sorting the array. Once sorted, we can iterate over the array to pick the element that appears for odd number of times.ExampleFollowing is the code −const arr = [20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5]; const findOdd = arr => { let ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
165 Views
We are required to write a JavaScript function that takes in an array that contains some numbers, some strings and some falsy values.Our function should return the biggest Number from the array.For example −If the input array is the following with some undefined values −const arr = [23, 'hello', undefined, null, 21, 65, NaN, 1, undefined, 'hii'];Then the output should be 65ExampleFollowing is the code −const arr = [23, 'hello', undefined, null, 21, 65, NaN, 1, undefined, 'hii']; const pickBiggest = arr => { let max = -Infinity; for(let i = 0; i < arr.length; i++){ ... Read More