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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:50:02+00:00 2026-05-23T01:50:02+00:00

Using Javascript, I have two arrays called array1 and array2. I set currentArrray to

  • 0

Using Javascript, I have two arrays called “array1” and “array2”.

I set currentArrray to be array1. Later when user clicks on some button, currentArray switches to Array2 and back to array1 if I click on it again.

This way, whenever there is any part of the code that needs to use an array, I just use something like in pseudocode:

{currentArray}.getText;
{currentArray}.getText;

Is it possible to do something like this? If so, how?
I know you can use if statement, but because currentArray is used in different parts of code, it would be nice if I had a simple way like this where all I have to modify is currentArray variable so I dont have if statements scattered all over the place checking what currentArray is.

  • 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-23T01:50:03+00:00Added an answer on May 23, 2026 at 1:50 am

    You can create a variable called “currentArray” and just set it to refer to whatever other array you want.

    var currentArray;
    
    currentArray = array2;
    

    If you’ve got some function that refers to a particular global variable:

    function foo() {
      // something something
      var x = array1[2];
      // ...
    }
    

    Then it’s going to refer to “array1” no matter what. You can change the value of “array1” of course, but you can’t make that function refer to “array2” any other way. Functions in JavaScript are immutable.

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

Sidebar

Related Questions

I'm interested in using a JavaScript Prompt to have the user enter data. Any
Suppose I have to access a some pattern of digit using javascript. Please have
I have two radio buttons with the same name. Using JavaScript, how can I
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I've been using javascript for a while, but have never learned the language past
I am creating a large table dynamically using Javascript. I have realised the time
I have a <select>. Using JavaScript, I need to get a specific <option> from
Does anyone know how to resize images proportionally using JavaScript? I have tried to
Is it possible to close parent window in Firefox 2.0 using JavaScript. I have
Can anyone help? I have been designing a site using Javascript but the rest

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.