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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:44:03+00:00 2026-05-21T06:44:03+00:00

I can’t figure out what’s going on here… I’m trying to copy an array,

  • 0

I can’t figure out what’s going on here… I’m trying to copy an array, and then shuffle and join the copy, but it just isn’t cooperating.

I have a JS file and am initializing a new array at the top:

var myArray = [];

On load of this JS file, I am pulling data from the Facebook API and stickin’ the results in myArray with some HTML around it.

I then have a function which I call on button click which creates a new variable from myArray and then joins and prints out the text in a div element:

var namesList = myArray;
namesList.join('');
$('#my_div').text(namesList);

It’s obviously been simplified, but the premise is the same.

My problem is, the array is not joining like it should. It remains in array form and nothing I’ve tried has fixed this. I’ve also tried:

var namesList = myArray.slice();

and

var namesList = myArray.slice(0);

to no avail.

HOWEVER: I can manipulate myArray with no problems in the same function and get the results I need. The problem with that is, I need to be able to shuffle the array each time the function is called and then print it out as text; this is why I am copying it in the first place.

For the life of me I can’t figure out why this isn’t working. All I need to do here is to create a copy of the variable within the scope of the function I’m calling, shuffle it, join it, and print it.

How do I fix this? OR, is there a better alternate? Many thanks in advance!

  • 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-21T06:44:04+00:00Added an answer on May 21, 2026 at 6:44 am

    The join() method returns a string rather than modifying the array reference – you need to change your code to this:

    var namesList = myArray;
    namelist = namesList.join('');
    $('#my_div').text(namesList);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can't work out a way to make an array of buttons in android. This
Can anyone help me trying to find out why this doesn't work. The brushes
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox
Can we put functions to determine the condition for our list comprehensions. Here is
Can someone help me? I am trying to do something like the following: #include
Can someone explain the usage of the dollar sign here.. var updateProgressDiv = $get('updateProgressDiv');
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of

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.