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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:12:30+00:00 2026-05-16T15:12:30+00:00

I have the following javascript which I need to make dynamic. data.addRows(2); data.setValue(0, 0,

  • 0

I have the following javascript which I need to make dynamic.

data.addRows(2);
data.setValue(0, 0, 'name goes here');
data.setValue(0, 1, value 1 goes here); 
data.setValue(0, 2, value 2 goes here); 
data.setValue(1, 0, 'name goes here');
data.setValue(1, 1, value 1 goes here); 
data.setValue(1, 2, value 2 goes here); 

I guess a loop is the best way to go forward:

I have come up with the following json structure:

[ 
    {"User1":{"value1": 50.00,"value2": "100"}}, 
    {"User2":{"value1": 10.00,"value2": "20"}}, 
    {"User3":{"value1": 10.00,"value2": "20"}}, 
    {"User4":{"value1": 10.00,"value2": "20"}}, 
    {"User5":{"value1": 20.00,"value2": "40"}} 
] 

I think this structure needs improving. Can someone please suggest a better structure to make it very easy for me to extract the data I want to extract from this?

  • 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-16T15:12:30+00:00Added an answer on May 16, 2026 at 3:12 pm
    var dataset = [
      {uid: 'user1', value1: 50.00, value2: 100},
      {uid: 'user2', value1: 10.00, value2: 20}, 
    ];
    

    That way you can do data.length to figure out how many values you have and you can loop a bit easier. For example:

    for(i = 0; i < dataset.length; i++) {
       console.log(data[i].uid);
    }
    

    Using your example:

    data.addRows(2); 
    var l = dataset.length, i, x = 0, y = 0;
    for(i = 0; i < l; i++) {
      data.setValue(y, x, dataset[i].uid); x++;
      data.setValue(y, x, dataset[i].value1); x++;
      data.setValue(y, x, dataset[i].value2); x=0;
      y++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JavaScript code: Link In which the function makewindows does not
I have the following javascript code, which loads without error, however the update function
I have the following code, which will not work. The javascript gives no errors
I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
I have the following javascript bookmarklet which opens a new popup window with a
I have the following simple javascript code, which handles the Return Key, I don't
I have the following JavaScript code to pop up a window in Internet Explorer.
I have the following javascript: css = document.createElement('style'); css.setAttribute('type', 'text/css'); css_data = document.createTextNode(''); css.appendChild(css_data);
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> 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.