簡體   English   中英

類型錯誤:無法讀取節點 js 中未定義的屬性(讀取“子字符串”)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM