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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:37:19+00:00 2026-06-15T11:37:19+00:00

I’m unsure what the problem is here, but here is my code var btotal

  • 0

I’m unsure what the problem is here, but here is my code

var btotal = [];
var songarray = [];
function whileplaying() {
    var playingSound = soundManager.getSoundById('aSound');
    for (var i=0;i<8;i++) {
        var ttotal = 0;
        for (var n=0;n<32;n++) {
            var eblock = (i*32)+n;
            ttotal = ttotal+(playingSound.eqData.left[eblock]*100);
        }
        ttotal = ttotal/32;
        btotal[i] = ttotal;
    }
    console.log(btotal);
    songarray.push(btotal);
}

To explain, while the sound is playing I get an array with a length of 8, summing up the EQ values of that frequency block. At the end I append this array to songarray, so the theory is that songarray is an array containing the sound’s EQ data in arrays.

The problem is that when I then get the value of songarray, it has however many arrays in it that I expected, but they are all identical, and are all what the last data point was, the latest value of btotal.

So this code would run, and console would display (for example):

[42.743750000000006, 2.98125, 0.10625000000000001, 0, 0, 0, 0, 0]
[38.859374999999986, 2.8, 0.09375, 0, 0, 0, 0, 0]
[56.26874999999998, 21.831250000000004, 3.853125, 0.340625, 0, 0, 0, 0]
[46.459374999999994, 19.584374999999998, 1.4, 0, 0, 0, 0, 0]
[38.08125, 11.8, 1.0750000000000002, 0, 0, 0, 0, 0] 

However the contents of song array goes like:

0: Array[8]
0: 38.08125
1: 11.8
2: 1.0750000000000002
3: 0
4: 0
5: 0
6: 0
7: 0
length: 8
__proto__: Array[0]
1: Array[8]
0: 38.08125
1: 11.8
2: 1.0750000000000002
3: 0
4: 0
5: 0
6: 0
7: 0
length: 8
__proto__: Array[0]

Which are all the contents of the latest btotal array. This leads me to believe that each entry in songarray merely points to btotal. So how do I make it so that each array in songarray is the value of btotal at the time I append it, and not merely a pointer?

  • 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-15T11:37:21+00:00Added an answer on June 15, 2026 at 11:37 am

    Define btotal within the scope of the function:

    var songarray = [];
    function whileplaying() {
        var btotal = [];
        var playingSound = soundManager.getSoundById('aSound');
        for (var i=0;i<8;i++) {
            var ttotal = 0;
            for (var n=0;n<32;n++) {
                var eblock = (i*32)+n;
                ttotal = ttotal+(playingSound.eqData.left[eblock]*100);
            }
            ttotal = ttotal/32;
            btotal[i] = ttotal;
        }
        console.log(btotal);
        songarray.push(btotal);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.