Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

react native - .replace function won't replace numbers in JavaScript?

I am trying to change all of the '%2F' and '%2B' into '/' and '+' in order to retrieve an URL from Firebase for an encoded image, but somehow it shows me an error of undefined is not an object (evaluating 'NewText.replace')

Here's the part of the code:

getURL(){
    db.ref('/').once('value', (data) =>{
        let RetrieveData=data.toString();
        var NewText = RetrieveData.photoPath;
        var FinalText = NewText.replace(/%2F/g, "/").replace(/%2B/g, "+"); 
        this.setState({
          urlHolder: FinalText, 
      })
    });
  }

Is it because the .replace function can't replace numbers? If so, what function should I use then?

question from:https://stackoverflow.com/questions/65937640/replace-function-wont-replace-numbers-in-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you read data from Firebase you get back a DataSnapshot object. To get the JSON value from that, you call .val() on that DataSnapshot.

So most likely what you're looking for is:

let RetrieveData=data.val();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...