【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“

简介: 【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“

报错问题

在使用 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
}
相关文章
|
11天前
|
iOS开发
部分库不支持32位系统archive报错:Undefined symbols for architecture armv7
部分库不支持32位系统archive报错:Undefined symbols for architecture armv7
15 0
|
19天前
|
JavaScript
报错 Cannot read properties of undefined(reading‘addEventListener‘)如何解决
报错 Cannot read properties of undefined(reading‘addEventListener‘)如何解决
42 1
|
19天前
|
缓存 JavaScript
报错:cannot read properties of undefined “reading url“
报错:cannot read properties of undefined “reading url“
|
19天前
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
|
19天前
|
编译器 程序员 API
【踩坑记录】解决GCC 中C++ 17 的 std::filesystem 链接报错:undefined reference to `std::filesystem::path
【踩坑记录】解决GCC 中C++ 17 的 std::filesystem 链接报错:undefined reference to `std::filesystem::path
164 4
|
19天前
|
Java 数据处理 Apache
Flink报错问题之Flink报错undefined如何解决
Flink报错通常是指在使用Apache Flink进行实时数据处理时遇到的错误和异常情况;本合集致力于收集Flink运行中的报错信息和解决策略,以便开发者及时排查和修复问题,优化Flink作业的稳定性。
|
19天前
|
JavaScript
【报错】Cannot read property ‘parseComponent‘ of undefined
【报错】Cannot read property ‘parseComponent‘ of undefined
237 2
|
19天前
|
JavaScript
【报错】:Cannot read properties of undefined (reading ‘prototype‘)
【报错】:Cannot read properties of undefined (reading ‘prototype‘)
191 0
|
19天前
|
JavaScript
JS中Null和Undefined的区别及用法
JS中Null和Undefined的区别及用法
17 1
|
19天前
|
JavaScript 前端开发 算法
undefined与null的区别
在JavaScript中,undefined和null都表示变量未被赋值或值缺失,但它们在使用场景上有一些区别。 - **`语义不同`**:undefined表示一个变量未被赋值或者声明后未进行初始化。而null表示一个变量被明确地设置为无值或者表示空值的概念。 - **`类型不同`**:undefined是一种基本数据类型,而null是一个引用类型。 - **`条件判断`**:在条件判断中,使用if (variable === undefined)或者if (variable === null)可以进行区分。