Is there a way to display the null element when concatenated to a string?
var arr = [];
arr.push('x');
arr.push(null);
arr.push('z');
// arr = ['x', null, 'z']
var samp = 'Array elements are: ' + arr;
// Array elements are: 'x',,'z'
Output that I want:
Array elements are: 'x', null,'z'
You can apply String to the arguments using Array.map. It's very succinct:
arr.map(String)
var arr = [];
arr.push('x');
arr.push(null);
arr.push('z');
var samp = 'Array elements are: ' + arr.map(String);
console.log(samp);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With