I have one requirement which needs my string to allow whitespace after every comma.My Array looks like this ['yes', 'no']. While converting this to string it became in the order of yes,no but I want the output to be like this yes, no allowing whitespaces after every comma.
let array=['yes', 'no'];
let result = array.toString().substring(0, (array.toString()).length).split(",");
console.log(result);
Answer was like yes,no but I need it to be yes, no. Is the any way by which I can get this output as a result.
CodePudding user response:
let array=['yes', 'no'];
console.log(array.join(', '))
CodePudding user response:
Try
let array=['yes', 'no'];
let result = array.toString().substring(0, (array.toString()).length).split(",").join(', ');
console.log(result);
CodePudding user response:
let array=['yes', 'no'];
let result = array.join(', ');
console.log(result); // Outputs - "yes, no"
CodePudding user response:
$(document).ready(function () {
let array = [' yes', ' no'];
var i = "";
$.each(array, function (index,value) {
i = i value;
});
console.log(i);
});