Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How I can use a variable as part of a instance name

Inside jQuery, I need to call a javascript instance.
This is an instance of splidejs.com inside of bricksbuilder.io.
The aim is to switch to a certain slide, for example:

bricksData.splideInstances.alfhxo.go(0);
bricksData.splideInstances.dxtzad.go(0);

As you can see, dynamically I need to change the third part of the instance name (which references the respective Splide attribute).

I tried to include the variable in different ways (at the end only guessing).
But -of course- this is not working:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

var_gamma = dxtzad;

'bricksData.splideInstances.' + var_gamma + '.go(1)';
bricksData.splideInstances.var_gamma.go(0);
bricksData.splideInstances.[var_gamma].go(0);
bricksData.splideInstances.$(var_gamma).go(0);

Any idea how I can this achieve?
If more context is needed, please let me know.

>Solution :

Just use the [ notation ]:

var gamma = "dxtzad";
bricksData.splideInstances[gamma].go(0);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading