Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
¿Cómo puedo mostrar que la segunda matriz de la cadena proviene de .split ()?

tengo esta cadena

 a = "This is just an example";

si lo usara

 split(" ",1)

imprimirá la primera palabra como una matriz.

Mi pregunta es ¿cómo puedo dividir solo la segunda cadena como una matriz?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use un límite de 2, luego corte a partir del segundo elemento.

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

O divida la cadena con un límite de 2, luego use una matriz literal que contenga solo el segundo elemento.

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

about 4 years ago · Juan Pablo Isaza Report

0

Un mejor enfoque sería dividir en un espacio y eso le dará una serie de cadenas, seleccione el índice que desea y divídalo aún más

Nota: EL ÍNDICE DE ARRAY COMIENZA DESDE 0 NO UNO, POR LO QUE SI QUIERES LA SEGUNDA CADENA, TENDRÁS QUE UTILIZAR EL ÍNDICE 1, NO 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' ]

Explicación :

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!