[英]Issue when retrieving data from an API in react and node js : TypeError: Cannot read properties of undefined (reading '0')
[英]TypeError: cannot read properties of undefined (reading 'substring') in node js
我正在嘗試獲取字符串的一部分。
let someValue = 'basic jkclwkjkvhrvhkuirhiehvyrbuyrbevnervnhrev';
let getSubstringValue = someValue.substring(6);
但是,在我的節點 JS 服務器中,
TypeError: Cannot read properties of undefined (reading 'substring')
還使用了“substr”和“ this answer ”。 但它也給出了這個“TypeError: Cannot read properties of undefined (reading 'substr')”錯誤。
如果它是一個字符串,你能調試someValue
嗎?
如果它是undefined
,你會得到錯誤TypeError: Cannot read properties of undefined
子字符串的簡單示例:
exampleVal = 'test';
// remove the first character
exampleVal = exampleVal.substring(1);
// show results (output is 'est')
console.log(exampleVal);
// example for if exampleVal is undefined
let exampleVar = undefined;
exampleVar = exampleVar.substring(1);
console.log(exampleVar);
// error is thrown
// TypeError: Cannot read properties of undefined (reading 'substring')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.