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

152
Vistas
How to add new lines inside of the object?

I've got this piece of code and I need to add inside of this.info().Info a new lines after each 10 words. I'm not very familiar with JavaScript and I'm learning it, but I don't know how to do this. this.info().Info stores Lorem Ipsum text that is written inside of a field and than saved.

 $(this.data()).after('<tr class="info-row"><td colspan="100"><div>' + this.info().Info + '</div></td></tr>');
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use the mod (%) operator, which returns the remainder of x / y, for that. You can loop through each word to check if the index is divisible by 10 and if it is, add a \n.

Here is how to do that:

function addNewlineEvery10Lines(text) {
  return text.split(" ").map((word, index) => { // get the words in an array and loop through them
    if ((index + 1) % 10 === 0) return word + "\n"; // add newline if divisible by 10
    return word; // just return word otherwise
  }).join(" "); // join the array back up
}

You can now use this function on the info.

 $(this.data()).after('<tr class="info-row"><td colspan="100"><div>' + addNewlineEvery10Lines(this.info().Info) + '</div></td></tr>');
about 4 years ago · Santiago Trujillo 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