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 6922403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:24:05+00:00 2026-05-27T10:24:05+00:00

Is there any trouble splitting variables that were previously split and overwrite the original

  • 0

Is there any trouble splitting variables that were previously split and overwrite the original variable while doing so?

Example:

arr = str.split(" ");
arr = arr[0].split("/");

I tested it and it works. But:

  • Is it risky to do this?
  • Will it behave as I expect at all times, and on all browsers?
  • 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-27T10:24:05+00:00Added an answer on May 27, 2026 at 10:24 am

    That will be fine in all browsers. There’s no risk.

    You are simply assigning the variable arr to refer to something new, it doesn’t matter what it used to refer to. (This doesn’t actually “overwrite the older array”, but if there are no other references to the old array the garbage collector will take care of it.)

    You can also do it in one line:

    arr=str.split(" ")[0].split("/");
    

    Note that according to MDN, .split() always returns an array with at least one element, even if the source string was empty or didn’t contain the separator.

    EDIT: If both source string and separator are empty strings .split() seems to return an empty array. I.e., "".split("") returns []. Thanks Munim for pointing that out. (But "".split(" ") returns [""] so there will be no problem for purposes of this question.)

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

Sidebar

Related Questions

I'm having trouble finding an open-source IDE with support for Git. Are there any
Is there any free or commercial component written in .NET (no COM interop) that
Is there any efficiency difference in an explicit vs implicit inner join? For example:
Are there any plugins or tools that can examine HTML and related CSS files
Are there any other characters except A-Za-z0-9 that can be used to shorten links
Possible Duplicate: PHP pagination class are there any PHP/Class libraries that i can utilize
I'm having trouble with a liferay installation that is suddenly (without any code modifications)
Is there any event handler before onLoad/onPageShow? The trouble with onLoad is if there
Is there any SQL SELECT query that can be done in oracle to detect
Is there any chance I'll run into trouble checking coverage with release code in

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.