Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6933413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:49:47+00:00 2026-05-27T11:49:47+00:00

Lets say I have a textarea with this text: first line some text. second

  • 0

Lets say I have a textarea with this text:

  1. first line some text.
  2. second line, other text. next line will be empty.
  3. (empty line)
  4. (empty line)
  5. last line here

As you can see, lines 3 and 4 are empty (\n). I need to get the exact lines structure (with empty lines as well) and convert it to an array. Each line is an element of the array. This is my current code:

var lines = $('#q').val().split(/\n/);
alert(lines.length); //using alert() because IE doesn't support console.log()
var texts = [];
for(i = 0; i < lines.length; i++) {
    texts.push($.trim(encodeURIComponent(lines[i])));
}

It works great on all browsers, except IE. For some reason, the split() function ignores empty lines (3 and 4) in IE. Because of that, they are never passed into the array :s

Solution by Squeegy in the comments

Replace split(/\n/) with split("\n") – damn you IE!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:49:47+00:00Added an answer on May 27, 2026 at 11:49 am

    The regex split is behaving strangely in IE8 and lower. Use a string comparison instead and it seems to work (fiddle)

    testText.split("\n")
    

    rather than

    testText.split(/\n/)
    

    [Edit] From Steven Levithan’s Blog:

    Internet Explorer excludes almost all empty values from the resulting
    array (e.g., when two delimiters appear next to each other in the
    data, or when a delimiter appears at the start or end of the data)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this: first \n\n\n second I want to display that on
Lets say I have a Label, Button, or TextArea object, that contains some amount
Let's say I have an html form. Each input/select/textarea will have a corresponding <label>
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say I have an array like this: string [] Filelist = ... I
I have a textarea element what i want to limit to, lets say, 100
Lets say we have this code: <div id='m1'> <div class=c></div> <div class=c></div> <div class=c></div>
Lets say I have this SQL statements: ALTER TABLE dbo.[tbl] ALTER COLUMN col1 varchar(300)
Let's say I have this javascript: <script language=javascript type=text/javascript> function addtext() { var newtext
Lets say i have a piece of code like this: test pattern | pattern

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.