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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:36:01+00:00 2026-05-26T04:36:01+00:00

Well, I have a lot of variables in javascript that I need get the

  • 0

Well, I have a lot of variables in javascript that I need get the values(that I getting from other page).
What’s the best way to do this?
I’m using the Microsoft.Jscript class and your methods for it work.

I written the following code:

    static Dictionary<string, string> ParseVariables(string code)
        {

            string[] variables = code.Split(';');
            Dictionary<string, string> variablesValues = new Dictionary<string, string>();
            for (int i = 0, len = variables.Length - 1; i < len; i++)
            {
                string vvar = variables[i];
                string varName = Regex.Replace(vvar.Split('=')[0], @"^\s*var\s*", string.Empty).Trim();
                var compiler = Compile(vvar);                
               string varValue = compiler.ToString();
                variablesValues.Add(varName, varValue);
            }

            return variablesValues;

        }        


static object Compile(string JSource)
        {
            return Microsoft.JScript.Eval.JScriptEvaluate(JSource, Microsoft.JScript.Vsa.VsaEngine.CreateEngine());
        }

This works fine to some cases,like:

var jscript = "var x = 'foo'; var y = 'baa';"; 
var output = ParseVariables(jscript); 
var val = output["y"]; //baa 
var val2 = output["x"]; //foo

but to cases like this:

var jscript = "var x = {}; x['foo'] = 'baa'; x['baa'] = 'test';"; 
var output = ParseVariables(jscript); 
var val = output["x['foo']"]; //not works 

How I do this? Any help is appreciated! Thanks!

  • 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-26T04:36:02+00:00Added an answer on May 26, 2026 at 4:36 am

    Since your approach is to split the JScript source code in chunks separated by semicolon (;), only the part between var and ; will be compiled using your Compile method.

    If you change your JScript source code into var x = { "foo": "baa", "baa": "test" };, the Compile method will work properly, and it will return a ScriptObject object.

    But then, there is another error – you are using ToString before you insert the value into the resulting Dictionary.

    Try this out to get started in a better direction:

    Change the Compile method into returning ScriptObject, like this:

    static ScriptObject Compile(string JSource)
    {
        return (ScriptObject)Microsoft.JScript.Eval.JScriptEvaluate(JSource, Microsoft.JScript.Vsa.VsaEngine.CreateEngine());
    }
    

    Then try this:

    var x = Compile("var x = { foo: 'baa', bar: { 'nisse': 'kalle' } };");
    
    var foo = x["foo"];
    var bar = (ScriptObject)x["bar"];
    var nisse = bar["nisse"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read a lot of articles on Dependency Injection as well as watched
well i have this messages table with sample values like these: msg_id recipient_id read
Well I have this MySQL stored procedure that I wrote and if I run
Well I have a series of sps that are running a data warehousing solution
I have one paragraph of javascript code. And i don't understand it very well.
Suppose I have a script that does a lot of stuff, and doesn't work
I have a script that I run which does a lot of tasks and
I have a lot of different servers that I connect to. Each time I
I have a lot of code that uses C style variable arguments. The code
I would like to list all the variables that have been declared in my

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.