js: TypeError: Cannot read property ‘replace’ of undefined using

If these values are getting fetched from a remote server then the case might be that you are trying to replace the characters before the data is assigned to the variable. Try using await functions or the .then() And also replace as such var vcap_servces_as_single_line = vcap_services?.replace(/\r?\n|\r/g, " ");

So that the code will not scream at you if you have an undefined value.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top