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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:39:06+00:00 2026-05-26T09:39:06+00:00

//window[Fluent][Include] function setGlobalVariableByName(name,value) { var indexes = name.split(.); var variable = null; $.each(indexes, function()

  • 0
//window["Fluent"]["Include"]

function setGlobalVariableByName(name,value)
{
    var indexes = name.split(".");
    var variable = null;
    $.each(indexes, function()
    {
        if (variable == null){
            variable = window[this];
        }else{
            variable = variable[this];
        }
    });

    variable = value;
}

setGlobalVariableByName("Fluent.Include.JqueryPulse",true);
console.log(Fluent.Include.JqueryPulse) // prints false

this doesn’t work, obviously. It would work if I just wanted to get the variable’s value, but not for setting it.

window["Fluent"]["Include"]["JqueryPulse"] = true;
console.log(Fluent.Include.JqueryPulse) // prints true

how could I achieve something like this without using eval?
I’d need some way to programmatically add array indices to this, I’d guess


The following works, can you suggest a better way to code it in order to make it more DRY?

function setGlobalVariableByName(name,value)
{
    var indices = name.split(".");
    var parent;
    $.each(indices, function(i)
    {
        if(i==indices.length-1){
            if (!parent){
                window[this] = value;
            }else{
                parent[this] = value;
            }
        }else if (!parent){
            parent = window[this];
        }else{
            parent = variable[this];
        }
    });
}

setGlobalVariableByName : function(name, value)
{
    var indices = name.split(".");
    var last = indices.pop();
    var parent;
    $.each(indices, function(i)
    {
        if (!parent){
            parent = window[this];
        }else{
            parent = variable[this];
        }
    }); 
    if (!parent){
        window[last] = value;
    }else{
        parent[last] = 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-05-26T09:39:06+00:00Added an answer on May 26, 2026 at 9:39 am

    You need to call

    variable[this] = value 
    

    somehow. So you need to break the loop of the splited string before reching the last name, and then assign the value.

    Ultimatively you need to call:

    variable = window['Fluent']['Include']; // build this in a loop
    variable['JqueryPulse'] = someValue; // then call this
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Opened Window: window.opener.variable = document.getElementById(target).value; //string window.opener.focus(); Window Opener alert(variable); Could this be done?
window.addEventListener('unload', function(e) { MyClass.shutdown(); window.removeEventListener('unload', /* how to refer to this function? */); },
window.popup = window.open($(this).attr('href'), 'Ad', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); $(window.popup).onload = function() { alert(Popup has loaded a page);
window.global_array = new Array(); window.example = function() { var x = new Object(); x['test_property']
$(window).load(function(){ alert(typeof $.fn.init_deps); }); $(document).ready(function(){ /* Departments switcher */ $.fn.init_deps = function(s){ var o
window.onload = raknaUtMedelvarde; function raknaUtMedelvarde(){ var tabell = document.getElementById(temperaturtabell); var rader = tabell.getElementsByTagName(tr); for
window.onload=function(){ var container = document.getElementById('container'), template = '<li>\ <input type=checkbox>\ </li>\ <li>\ <input type=checkbox>\
window.oncontextmenu = function() { return false; }; Will this work on all major browsers
Window.open javascript function is not working in Mozilla, but working in other browsers, here
The window pops up below the variable, and obscures the code I want to

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.