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

  • Home
  • SEARCH
  • 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 1074501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:08:03+00:00 2026-05-16T21:08:03+00:00

How do I parse through an array and for each element multiply its value

  • 0

How do I parse through an array and for each element multiply its value field by ‘x’

I want to pass through a a native array that contains 60 elements as follows:

[
     [value, key], [value, key], [value, key] 
]

In the above example the key field will be a number starting at 60 and counting down to 0.

The value field can be any number.

This array is built live starting from when it is passed it’s first value, holding up to a maximum of 60 values elements, with the key for each value starting at 60.

Every seccond a new value is passed to the array and the oldest value is taken out. 0 is removed 60 is added and everything else is bumped down by 1.

Whenever this update takes place of adding a new value to the array, I also want to parse through the entire array and multiply the “value” field by ‘x’. Lets say for example purposes that x is equal to 1.2.

This means that everytime the update is run the first value is multiplied by 1.2, the 2nd element’s value is multiplied by 1.2 the third elements is multiplied by 1.2 and so on.

Meaning that by the time it reaches a “key” of 0 being the last element it will have been multiplied by 1.2 60 times.

Example of actual data:

[[-30.4901691201296, 60], [-30.1833776214304, 59], [-29.7627840450973, 58], [-29.3947583209356, 57], [-28.9645892754055, 56], [-28.6354656536817, 55], [-28.2921821871286, 54], [-27.9905577131509, 53], [-27.7947946913668, 52], [-27.6543340290543, 51], [-27.6519828946371, 50], [-27.6173533427694, 49], [-27.5554196324518, 48], [-27.4347081962877, 47], [-27.3527616238956, 46], [-27.1500146810747, 45], [-26.9074687550566, 44], [-26.5520557024907, 43], [-26.3778269233317, 42], [-26.2025741177589, 41], [-25.9715337718657, 40], [-25.7909728444171, 39], [-25.6446160165696, 38], [-25.7040560541356, 37], [-25.8676731838619, 36], [-26.1857049460322, 35], [-26.5338463742982, 34], [-26.8991378853451, 33], [-27.0722352574209, 32], [-26.9933000067798, 31], [-26.5736545189266, 30], [-25.5369071865736, 29], [-24.0243166908922, 28], [-22.2063720253207, 27], [-20.4275559328569, 26], [-19.0900734751772, 25], [-17.9226541769101, 24], [-17.2615147887497, 23], [-16.8724851836878, 22], [-16.7577128443888, 21], [-17.1571347530026, 20], [-17.6471873975822, 19], [-18.6461197175468, 18], [-19.8885692353328, 17], [-21.2039894571651, 16], [-23.0079052401369, 15], [-25.1005655769037, 14], [-27.342591130044, 13], [-29.7388646710222, 12], [-32.1429579450835, 11], [-34.5906266190624, 10], [-37.0391503781189, 9], [-39.5315634976835, 8], [-41.9487262455882, 7], [-43.9289096382579, 6], [-46.00519229484, 5], [-48.6400387646249, 4], [-50.5736255352748, 3], [-52.8788720227602, 2], [-54.786535213712, 1]]

Current code:

This is my current usage for building the array:

setInterval(ExampleUsage, 1000);

function ExampleUsage() {
    $.getJSON(urlDefault, function (data) {
          RawDnD = data.DnD* 1;
          DnDData.unshift(RawDnD);
          DnDData = DnDData.slice(0, 60);
          DnDArray = $.map(DnDData, function (n, i) {
              return [[n, 60 - i]];
          });
          // Parse array here //
   });
}
  • 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-16T21:08:04+00:00Added an answer on May 16, 2026 at 9:08 pm

    I don’t think you can do what you’re asking. If read your code correctly, each second you’re rebuilding the array from JSON data. It’s trivial to loop through the array afterwards and multiply each element, but a second later your going to rebuild the array with the new data and lose those multiples.

    You could simulate the effect by doing this:

    var factor = 1.2;
    var multiplier = factor;
    for (i = 0; i < dataArray.length; i++) {
        dataArray[i] *= multiplier;
        multiplier *= factor;
    }
    

    Not sure if this is what you want, though.

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

Sidebar

Related Questions

I want to parse a config file sorta thing, like so: [KEY:Value] [SUBKEY:SubValue] Now
I want to parse some HTML in order to find the values of some
I am attempting to parse a string like the following using a .NET regular
I'm wanting to parse a string into a nullable int in C#. ie. I
I'm trying to parse a grammar in ocamlyacc (pretty much the same as regular
I'm trying to parse an INI file using C++. Any tips on what is
I would like to parse a string such as p1=6&p2=7&p3=8 into a NameValueCollection .
We use SAX to parse XML because it does not require the entire XML
I need to parse a xml file which is practically an image of a
I have used the XML Parser before, and even though it worked OK, I

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.