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

159
Views
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 answers
Answer question

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 Report

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