1

My example is paired down but I believe it communicates my problem:

I have a simple string var data = '360–400 ' for sake of example:

data.replace(' ');

returns:

//360–400undefined

Question: how do I make sure my output doesnt leave undefines in the string

0

1 Answer 1

2

You need to pass a second parameter to the .replace() method in order to replace the matched value. If you simply want to remove the value, just pass an empty sting, '':

data.replace(' ', '');

The reason it was replacing the value with undefined was simply because the second parameter was undefined.

Sign up to request clarification or add additional context in comments.

1 Comment

ugh. yup I'm dumb. beating my head on the desk for like 15mins on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.