Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
im geting [object Object] but i want to get text that in tags

can somebody say how to replace it ?

function textFormat(value){
        value = value.replace(/\*{2}(.*?)\*{2}/g, <strong>{'$1'}</strong>);
        value = value.replace(/\*(.*?)\*/g, <i>{'$1'}</i>);
        value = value.replace(/~{2}(.*?)~{2}/g, <s>{'$1'}</s>);
        value = value.replace(/_{2}(.*?)_{2}/g, <u>{'$1'}</u>);
        return value;
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It might help if you can show how you're getting the initial value that's being passed to the textFormat() function.

But in general it looks like the function expects a text string, but the value being passed to the function is an object.

MDN docs: Object

The best approach here would probably be to adjust the code outside of the function, so that when the textFormat() function is called, the value it's called with is a text string instead of an object.

Or, a more versatile solution would be to add an input handler at the top of textFormat() to handle different kinds of input differently:

function textFormat(inVal){

    // check input type
    let value;
    if (typeof inVal === 'object') {
    
        // input is an object, so we'll turn the
        // object into a JSON string
        
        value = JSON.stringify(inVal);
        
    } else {    
    
        // input is not an object, so we'll assume
        // it's a string
        
        value = inVal;
    }

    value = value.replace(/\*{2}(.*?)\*{2}/g, <strong>{'$1'}</strong>);
    value = value.replace(/\*(.*?)\*/g, <i>{'$1'}</i>);
    value = value.replace(/~{2}(.*?)~{2}/g, <s>{'$1'}</s>);
    value = value.replace(/_{2}(.*?)_{2}/g, <u>{'$1'}</u>);
    return value;
    
}

Note, however, that with the latter solution if you input an object, the return value will be a JSON-ified string of that object (with the given string replacements performed). If you want to get back a modified object, then you'll have to turn the JSON string back into an object after the string.replace() lines.

You can do that with JSON.parse()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!