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

161
Vistas
How Can I show the second array from string came from .split()

I have this string

a = "This is just an example";

If I used

split(" ",1)

it will print the first word as an array.

My question is how can I split just the second string as an array?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use a limit of 2, then slice starting from the second element.

a = "This is just an example";
console.log(a.split(" ", 2).slice(1));

Or split the string with a limit of 2, then use an array literal containing just the second element.

a = "This is just an example";
console.log([a.split(" ", 2)[1]]);

about 4 years ago · Juan Pablo Isaza Denunciar

0

A Better Approach would be to split on a space & that will give you an array of string, select the index you want & split it further

Note : ARRAY INDEX STARTS FROM 0 NOT ONE, SO IF YOU WANT THE SECOND STRING, YOU WILL HAVE TO USE THE INDEX 1, NOT 2

const  a = "This is just an example";
const secondWordArr = a.split(' ')[1].split('');
// secondWordArr represents the array of characters of the seconds word
console.log(secondWordArr); // Output [ 'i', 's' ]

Explanation :

a.split(' ')  // this splits the string into an array of strings/words
a.split(' ')[1] // Access the second string in the array of split strings/words
a.split(' ')[1].split('') // splits the second string from the array of strings/words into a separate array//

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