हमें एक JavaScript फ़ंक्शन लिखना होगा जो एक स्ट्रिंग लेता है और मूल स्ट्रिंग के सभी वर्णों को व्हाइटस्पेस हटाकर एक नई स्ट्रिंग लौटाता है।
उदाहरण
इसका कोड निम्नलिखित होगा:
const str = "This is an example string from which all whitespaces will be removed";
const removeWhitespaces = str => {
let newStr = '';
for(let i = 0; i < str.length; i++){
if(str[i] !== " "){
newStr += str[i];
}else{
newStr += '';
}
}
return newStr;
};
console.log(removeWhitespaces(str));
आउटपुट
कंसोल में आउटपुट:
Thisisanexamplestringfromwhichallwhitespaceswillberemoved