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 −


studentDetails = [
   [101, 'John', 'JavaScript'],
   [102, 'Bob', 'MySQL']
var studentFormat = '||Id||Name||subjName||
'; var seperate = ''; seperate = seperate + => `|${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.


This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo112.js