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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:17:57+00:00 2026-06-04T04:17:57+00:00

I have a data set as var data1 = {values:[ { X: 33, Y:

  • 0

I have a data set as

var data1 = {values:[
  { X: "33", Y: 12 },
  ....
  ]};
var data2 = { values:[
  { X: "Jan", Y: 2 },
  ...
  ]};

I want to load appropriate data set by

$(document).ready(function() {
  $(".test").click(function(){
  var data = $(this).val() // the value will be data1 or data2
           // how can I make the data a JSON equal to data1 or data2 instead of
           // assigning the static value of $(this).val() to it.
  }
});

How can I create the var data from the static value?

  • 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-04T04:17:58+00:00Added an answer on June 4, 2026 at 4:17 am

    Don’t.

    Have data1, data2 as properties of an object, and use the square bracket member operator to access them.

    var dataset = {
    
        data1: {
            values: [{
                X: "33",
                Y: 12
            }, ....]
        }
        data2: {
            values: [{
                X: "Jan",
                Y: 2
            }, ...]
        };
    }
    

    var data = dataset[$(this).val()]
    

    Although if your data1 and data2 are global variables, you could access them the same way from the window object.

    var data = window[$(this).val()]
    

    But an object like dataset is still nicer than a bunch of globals.

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

Sidebar

Related Questions

Lets say I have this data set... var a = [5,6,7]; var b =
I have a LINQ query that pulls ID values with integers: var data =
I have a data set that I receive from a service. The data comes
I have a data set that looks like this: This1 GH This2 GH This3
I have a data set in R as follows ID Variable1 Variable2 Choice 1
I have a data set with over 50,000 geocoded points (lat-long). Each point has
I have a data set which consists of an ID and a matrix (n
I have a data set that is around 700 rows with eight columns of
I have a data set that that I would like to call in a
I have a data set of item difficulties that correspond to items on a

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.