Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

257
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda