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

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

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 Relatório

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 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