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

208
Views
slice text in textbox after newline

I have a textbox in reactjs. I want to slice its contents by new lines, outputting an array.

For example, if the textbox has

foo
bar
foobar

I want to get

['foo', 'bar', 'foobar']

Any ways I can do this?

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

0

\n means new line, I suggest trimming the text before splitting.

string.trim().split('\n')
about 4 years ago · Juan Pablo Isaza Report

0

for that, you just need to use 'split' function with '\n' which will help you separate the text.

codesandbox example : https://codesandbox.io/s/vibrant-murdock-0rmku2?file=/src/App.js

about 4 years ago · Juan Pablo Isaza Report

0

We can use split() method here

let's consider an example
str = "x\ny";
console.log(str.split("\r\n"));
you may need to use '\r\n'

the output is ["x", "y"]

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!