当前位置:网站首页>【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
2022-07-05 00:05:00 【博客zhu虎康】
报错问题
在使用 split()方法分割成字符串时,报红信息如下:Cannot read properties of undefined (reading ‘split‘)
报错分析
在对数据进行分割以前,要先判断当前数据是否存在为空的情况;如果不对数据进行判断,可能会导致异常。所以在调用 splid() 函数前,需要对当前需要进行分割的数据进行非空的判断(或者是当数据不为空的情况下调用)。
报错解决
在对数据进行分割以前,要先判断当前数据是否存在为空的情况;如果不对数据进行判断,可能会导致异常。所以在调用 splid() 函数前,需要对当前需要进行分割的数据进行非空的判断(或者是当数据不为空的情况下调用)。
const imgUrl = "https://tu.cloud.cn/flower/flower-size.jpg?size=1800";
// 当数据不为空的情况下
if(imgUrl) {
// 截取 再拼接新的字符串
const newImgUrl = imgUrl.split('?')[0] + "?size=600";
console.log(newImgUrl); //https://tu.cloud.cn/flower/flower-size.jpg?size=600
}
边栏推荐
- Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
- Financial markets, asset management and investment funds
- 【雅思阅读】王希伟阅读P4(matching1)
- If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
- How to use fast parsing to make IOT cloud platform
- Five papers recommended for the new development of convolutional neural network in deep learning
- 取得PMP證書需要多長時間?
- 雅思考试流程、需要具体注意些什么、怎么复习?
- JS convert pseudo array to array
- go踩坑——no required module provides package : go.mod file not found in current directory or any parent
猜你喜欢
![[JS] - [sort related] - Notes](/img/b7/af467c7a169b73c3c4936072aef8b9.png)
[JS] - [sort related] - Notes

圖解網絡:什麼是網關負載均衡協議GLBP?

Acrel-EMS综合能效平台在校园建设的意义

Netcore3.1 JSON web token Middleware

How to effectively monitor the DC column head cabinet

Build your own minecraft server with fast parsing

青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区

Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
Date time type and format in MySQL

Jar批量管理小工具
随机推荐
挖财学院开户安全的吗?开户怎么开?
Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
快解析内网穿透帮助企业快速实现协同办公
如果炒股开华泰证券的户,在网上开户安全吗?
Five papers recommended for the new development of convolutional neural network in deep learning
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
How to use fast parsing to make IOT cloud platform
Application of multi loop instrument in base station "switching to direct"
Robot reinforcement learning synergies between pushing and grassing with self supervised DRL (2018)
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
[JS] - [dynamic planning] - Notes
How to apply for PMP project management certification examination?
Summary of week 22-07-02
P4408 [NOI2003] 逃学的小孩(树的直径)
Introduction to ACM combination counting
如何报考PMP项目管理认证考试?
[Peking University] tensorflow2.0-1-opening
ECCV 2022 | Tencent Youtu proposed disco: the effect of saving small models in self supervised learning
Expand your kubecl function