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
Selected Reading
Formatting text to add new lines in JavaScript and form like a table?
For this, use map() along with join(‘
’).Then ‘
’ is for new line. Following is the code −
Example
studentDetails = [ [101, 'John', 'JavaScript'], [102, 'Bob', 'MySQL'] ]; var studentFormat = '||Id||Name||subjName||
'; var seperate = ''; seperate = seperate + studentDetails.map(obj => `|${obj.join('|')}|`).join('
'); studentFormat = studentFormat + seperate; console.log(studentFormat);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo112.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo112.js ||Id||Name||subjName|| |101|John|JavaScript| |102|Bob|MySQL|
Advertisements
