当前位置:网站首页>js对返回的数据的各种数据类型进行非空判断。
js对返回的数据的各种数据类型进行非空判断。
2022-06-11 21:15:00 【浅浅一笑^*^】
图片:

总结:最近在写公司项目的时候碰到后台返回的数据有好几种类型的非空判断,试了好几种方法,记录一下。
解决方法如下:
//0 null undefined {}
//Object.keys:这个方法可以吧对象里面的key提取到一个数组里
//如果返回的后台数据不为空,执行下面的内容赋值。
if(!res.data||Object.keys(res.data).length==0)return
//当if的判断不为空,才会执行以下,需要执行的内容赋值语句
this.nums=res.data.Address;
this.isphone=res.data.CompanyPhone;
扩展知识:
逻辑运算符
&& 表达式:条件一 && 条件二 ,说明:仅仅两个条件同时为真,结果为真。
|| 表达式: 条件一 || 条件二, 说明:只要两个条件有一个为真,结果为真。
!表达式: !条件, 说明:条件为真时,他为假;条件为假时,他为真。
相等==:先强制转换变量类型,再比较。
全等===:不转换类型,一旦类型不同,就是不全等。
记录一下!
边栏推荐
- How to manually drag nodes in the Obsidian relationship graph
- Go语言for循环
- Tensorflow 2. X Getting Started tutorial
- JVM之堆区
- JVM heap
- [Monday commuter radio station] cron expression. It's enough to read this article
- Application business layer modification
- The scale of the global machine vision market continues to rise. Poe image acquisition card provides a high-speed transmission channel for industrial cameras
- Network security Kali penetration learning introduction to web penetration using MSF penetration to attack win7 host and execute commands remotely
- 全球机器视觉市场规模持续上涨,PoE图像采集卡为工业相机提供高速传输通道
猜你喜欢

Compilation process of program

频域滤波器

Chinese text classification based on CNN

Yintai department store and Taobao tmall jointly create a green fashion show to help "carbon neutrality"
![[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions](/img/1f/00f2085186971198928b012a3792ea.jpg)
[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions

Cuckoo Hash
Recompile kubeadm to solve the problem of certificate expiration in one year

Three waves of changes in cloud computing

Weekly 02 | pour être honnête, je suis un étudiant du MIT

Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
随机推荐
Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system
php pcntl_fork 创建多个子进程解析
Two end carry output character
IDEA中,运行yarn命令,显示无法加载文件,因为在此系统上禁用运行脚本
Vectordrawable error
Three waves of changes in cloud computing
Figure guessing game
【C语言进阶】整型在内存中的存储
Title does not display after toolbar replaces actionbar
[data visualization] use Apache superset to visualize Clickhouse data
Toolbar替换ActionBar后Title不显示
新品发布:LR-LINK联瑞推出首款25G OCP 3.0 网卡
Object creation process of JVM
One article to show you how to understand the harmonyos application on the shelves
Regular check matches positive integer or decimal limit between [0-100] and [0-1000]
Bug -- coredump usage
BUG -- coredump使用
Add personal statement for go file in file template in Golan
JVM之对象创建过程
电竞网咖用2.5G网卡,体验飞一般的感觉!