如何檢查JavaScript中的空字串? | js空白字元
![如何檢查JavaScript中的空字串?](https://i.imgur.com/axBPWDg.jpg)
英文原文地址為:HowdoyoucheckforanemptystringinJavaScript?Isawthisthread[2],butIdidntseeaJavaScriptspecificexample.Isthereasimplestring.EmptyavailableinJavaScript,orisitjustacaseofcheckingfor""?我看到了這個執行緒,但是我沒有看到一個JavaScript特定的例子。有一個簡單的字串。在JavaScript中是空的,還是隻需要檢查一下?30個解決方案#12613 Ifyoujustwanttocheckwhethertheresanyvalue,youcando如果你想檢查是否有任何值,你可以。if(strValue){//dosomething}Ifyouneedtocheckspecificallyforanemptystringovernull...
![如何檢查JavaScript中的空字串?](http://pix1.agoda.net/hotelimages/300/3008492/3008492_17121510550060424840.jpg?s=800x)
I saw this thread[2], but I didnt see a JavaScript specific example. Is there a simple string.Empty available in JavaScript, or is it just a case of checking for ""?
我看到了這個執行緒,但是我沒有看到一個JavaScript特定的例子。有一個簡單的字串。在JavaScript中是空的,還是隻需要檢查一下?
30 個解決方案#12613
If you just want to check whether theres any value, you can do
如果你想檢查是否有任何值,你可以。
if (strValue) { //do something }If you need to check specifically for an empty string over null, I would think checking against "" is your best bet, using the === operator[3] (so that you know that it is, in fact, a string youre comparing against).
如果您需要專門檢查空字串,那麼我認為檢查“”是您最好的選擇,使用===操作符(這樣您就知道它實際上是一個您正在比較的字串)。
#2867
For checking if a string is empty, null or undefined I use:
用於檢查字串是否為空、null或未定義的I:
function isEmpty(str) { return (!str || 0 === str.length); }For checking if a string is blank, null ...
取得本站獨家住宿推薦 15%OFF 訂房優惠
本站住宿推薦 20%OFF 訂房優惠,親子優惠,住宿折扣,限時回饋,平日促銷
DOM 中的空白字元 | js空白字元
字串 | js空白字元
js判斷輸入字串是否為空、空格、null的方法總結 | js空白字元
js判斷為空Null與字串為空簡寫方法 | js空白字元
如何檢查JavaScript中的空字串? | js空白字元
js判斷輸入字串是否為空、空格、null總結 | js空白字元
【JS】----js去除字串空格 | js空白字元
String.trim()將字串去空白 | js空白字元
JavaScript substr 與substring 的差異 | js空白字元
JavaScript 取得字串長度的判斷length | js空白字元
DOM 中的空白字元 | js空白字元
String.prototype.trim() - JavaScript | js空白字元
JavaScript到底會把哪些字元當作是空白字元? | js空白字元
[JavaScript]去除左右空白、左空白、右空白使用正規表示式 | js空白字元
javascript几种写空格符的方法转载 | js空白字元
HTML 空格與空白字元使用(包含 與全形空白) | js空白字元
[JavaScript筆記]如何移除字串中的所有空格? | js空白字元
[javascript] 利用trim() 去掉字串前後的空白字元 | js空白字元
String.prototype.padStart() | js空白字元
10 | js空白字元
![](https://i.imgur.com/axBPWDg.jpg)