How to determine if the message is blank in the frontend of the mini program
Method: You can encapsulate a function that determines whether the object is empty, such as isBlank in the following code.
function isBlank(str){ if (Object.prototype.toString.call(str) ==='[object Undefined]'){//空 return true } else if ( Object.prototype.toString.call(str) === '[object String]' || Object.prototype.toString.call(str) === '[object Array]') { //字条串或数组 return str.length==0?true:false } else if (Object.prototype.toString.call(str) === '[object Object]') { return JSON.stringify(str)=='{}'?true:false }else{ return true } }
Use isBlank to judge whether the message is empty:
if(isBlank(message)){ console.log('消息为空') }else{ console.log('消息:' + message) }
PHP Chinese website, a large number of free small program development tutorials, welcome to learn!
The above is the detailed content of How to determine if a message is blank in the frontend of the mini program. For more information, please follow other related articles on the PHP Chinese website!