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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:14:33+00:00 2026-06-08T04:14:33+00:00

I have a script setup like this (http://jsfiddle.net/YD66s/): var countFull = new Array(0,1,2,3,4,5,6); var

  • 0

I have a script setup like this (http://jsfiddle.net/YD66s/):

var countFull = new Array(0,1,2,3,4,5,6);
var countActive = new Array(0,1,2,3,4,5,6);

function pickRandom(a) {
  if(arguments[1].length == 0) {
      arguments[1] = arguments[0];
  }

  var m = Math.floor(Math.random()*arguments[1].length);
  chosen = arguments[1].splice(m,1);

  return chosen;
}

setInterval(function() {
  pickRandom(countFull,countActive);
}, 1000);

When I run this I want the variable to be set for that function only. Instead it is affecting countFull towards the end because I make arguments[1] = arguments[0]. How in javascript can I just reference a variable but not consume it and ultimately arguments[1] becomes arguments[0].

Hope this makes sense. This is driving me nuts how different javascript variables are compared to other languages like PHP.

  • 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-06-08T04:14:35+00:00Added an answer on June 8, 2026 at 4:14 am

    Javascript arrays are just pointers so when you do arguments[1] = arguments[0] you actually just set the pointer but the underlying arrays are the same. As a result, every time you modify arguments[1] you also modify arguments[0]. To do what you want, you need to copy the array. You could do it this way:

    if (arguments[1].length == 0) {
      for(var i = 0; i < arguments[0].length; i++) {
        arguments[1][i] = arguments[0][i];
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a php script to receive url data like this: http://giffgaff.liamwli.co.uk/?name=liamwli
Say I have a set-up like this: $('#mylink').click(function(event){ savePost(); }); <a id=mylink href=http://google.com>my link</a>
I have a system setup like this: http://joemaller.com/990/a-web-focused-git-workflow/ However no matter how I configure
I have a div:hover script set up http://jsfiddle.net/4wb5P/6/ (with the help of from StackOverflow
I have a simple inno-setup script that allows my setup to install either the
i have setup an overlay script to enable me to display an overlay popup
I have a SSIS 2008 script component which is setup as a transform (so
I have an image uploading script in which i use the following setup to
I have this script set up that echoes all relevant users in a database
In my global.asax I have url routing setup like below: routes.MapPageRoute(User Logon, {Vendor}/Logon, ~/Logon.aspx);

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.