Home>Article>WeChat Applet> How to determine if a message is blank in the frontend of the mini program

How to determine if a message is blank in the frontend of the mini program

angryTom
angryTom Original
2020-03-26 11:39:35 2658browse

How to determine if a message is blank in the frontend of the mini program

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 freesmall program developmenttutorials, 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn