Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
how can i map the string that are in the object where empty string considered as empty line and each string restricted to one line
{
"ptr0": [
    "Interviewer: Nancy Carolyn Camp Foster (NF)",
    "",
    "Interviewee: Edith Mills (EM)",
    "",
    "NF: Well it's kind of interesting to observe how students have turned out who've",
    "gone through Bristow schools. We lose track, we don't really realize and",
    "",
    "Other Persons: Lucy Mae Mills (LM) Unknown Woman (WS)"
        ]
}

I am trying to map the above objecttrans object ptr0 in jsx in browser where i want empty string in object to be considered as a empty line and each string in an object restricted to one line, something like this i am trying to show in browser jsx:

Interviewer: Nancy Carolyn Camp Foster (NF)

Interviewee: Edith Mills (EM)

NF: Well it's kind of interesting to observe how students have turned out who've
gone through Bristow schools. We lose track, we don't really realize and

Other Persons: Lucy Mae Mills (LM) Unknown Woman (WS)

Component where I am calling the Transcript Component

<Transcript
                transcript={objecttrans.ptr0.map(pt=>{          
                return   pt               
        })}
        />

Transcript Component

return (
    <>
      <div className="content">
           <p>{props.transcript}</p>
      </div>
    </>
  );
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Join the array of lines into a single string using newlines:

const text = lines.join('\n');

Then put the text into a preformatted text element <pre> instead of a paragraph element <p> and style however you'd like.

const lines = [
  "Interviewer: Nancy Carolyn Camp Foster (NF)",
  "",
  "Interviewee: Edith Mills (EM)",
  "",
  "NF: Well it's kind of interesting to observe how students have turned out who've",
  "gone through Bristow schools. We lose track, we don't really realize and",
  "",
  "Other Persons: Lucy Mae Mills (LM) Unknown Woman (WS)",
];

const text = lines.join('\n');

document.querySelector('pre').textContent = text;
<pre></pre>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Your code seems to be doing what you want it to do. If your issue was that new lines are not being shown, you can just return a br element when the string is empty. Something like:

objecttrans.ptr0.map(pt => pt || <br />

const Transcript = props => <div className="content">
  <p>{props.transcript}</p>
</div>;


const objecttrans = {
  "ptr0": [
    "Interviewer: Nancy Carolyn Camp Foster (NF)",
    "",
    "Interviewee: Edith Mills (EM)",
    "",
    "NF: Well it's kind of interesting to observe how students have turned out who've",
    "gone through Bristow schools. We lose track, we don't really realize and",
    "",
    "Other Persons: Lucy Mae Mills (LM) Unknown Woman (WS)"
  ]
};

ReactDOM.render(
  <Transcript
    transcript={objecttrans.ptr0.map(pt => pt || <br />)}
  />, document.body
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda