简体   繁体   中英

TypeError: cannot read properties of undefined (reading 'substring') in node js

I am trying to get a part of a string.

let someValue = 'basic jkclwkjkvhrvhkuirhiehvyrbuyrbevnervnhrev';
let getSubstringValue = someValue.substring(6);

But, in my node JS server gives,

TypeError: Cannot read properties of undefined (reading 'substring')

Also used 'substr' using ' this answer '. But it also gave this 'TypeError: Cannot read properties of undefined (reading 'substr')' error.

Can you debug someValue if it is a string?
If it's undefined , you get the error
TypeError: Cannot read properties of undefined

Simple example of substring:

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM