Using .join() method
1) Using .join() method example one
// Convert to Mango * Orange * Banana * Grapes * Pineapple
// 0 1 2 3 4
const fruits = ['Mango', 'Orange', 'Banana', 'Grapes', 'Pineapple'];
console.log('This is an Array:', fruits);
// Create a String variable and use the .join(' * ') method
const string = fruits.join(' * '); // instead of * we can use anything
console.log('This is a string:', string); // default seperator of string is comma (,)
===============================================================================================
TERMINAL:
2) example 2 using \n
// using \n
// 0 1 2 3 4
const fruits = ['Mango', 'Orange', 'Banana', 'Grapes', 'Pineapple'];
console.log('This is an Array:', fruits);
// Create a String variable and use the .join('\n') method
const string = fruits.join('\n'); // instead of \n we can use anything
console.log('This is a string:', string); // default seperator of string is comma (,)
==========================================================================================
TERMINAL:


Comments
Post a Comment