একটি স্ট্রিং-এ হোয়াইটস্পেস চেক করতে, 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