Was it helpful?

Question


For this, use map() along with join(‘\n’).Then ‘\n’ is for new line. Following is the code −

Example

studentDetails = [
   [101, 'John', 'JavaScript'],
   [102, 'Bob', 'MySQL']
];
var studentFormat = '||Id||Name||subjName||\n';
var seperate = '';
seperate = seperate + studentDetails.map(obj =>
`|${obj.join('|')}|`).join('\n');
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|
raja
Published on 09-Sep-2020 13:07:43

Was it helpful?
Not affiliated with Tutorialspoint