- 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
How to concatenate the string value length -1 in JavaScript.
For this, use join(). It will concatenate the string value length-1.
Example
Following 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.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo274.js JohnJohnJohnJohnJohn JohnJohnJohnJohn
Advertisements