
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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|
- Related Articles
- Formatting JavaScript Object to new Array
- How to create a new table from the first table using MySQL LIKE?
- How to add a new row in a table using jQuery?
- Add new MySQL table columns and create indexes?
- Formatting Text in CSS
- Add plain text next to a form label within a form with Bootstrap
- HTML Text Formatting
- How to add a new element to HTML DOM in JavaScript?
- How to set the distance between lines in a text with JavaScript?
- String Formatting in C# to add padding
- How to add a new column Address in the above DB2 table TAB1?
- How to add two arrays into a new array in JavaScript?
- How to add a new column to an existing table of Laravel in a migration?
- Add a new column and index to an existing table with ALTER in a single MySQL query?
- Formatting Text Using CSS

Advertisements