স্ট্রিং-এ হোয়াইটস্পেস যাচাই করতে indexOf(' ') কনসেপ্ট ব্যবহার করুন। নিচে কোডটি দেওয়া হল:
উদাহরণ
function stringHasTheWhiteSpaceOrNot(value){
return value.indexOf(' ') >= 0;
}
var whiteSpace=stringHasTheWhiteSpaceOrNot("MyNameis John");
if(whiteSpace==true){
console.log("The string has whitespace");
} else {
console.log("The string does not have whitespace");
}
উপরোক্ত প্রোগ্রাম চালানোর জন্য নিচের কমান্ডটি ব্যবহার করুন:
node fileName.js
এখানে, আমার ফাইলের নাম demo108.js।
আউটপুট
এটি নিচের আউটপুটটি তৈরি করবে:
PS C:\Users\Amit\JavaScript-code> node demo108.js The string has whitespace