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

A string as part of an expression

How can I pass a part of an expression as an argument as a string? Something like this:

let t = "val";
$('.class').t();

UPD

enter image description here

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

enter image description here

UPD 2

My mistake, I was just redefining an already declared variable.

>Solution :

You can use Bracket notation to access the property of an object dynamically:

let t = "val";
$('.class')[t]();

This will call the method with the name that matches the value of the t variable on the jQuery object with the class. If the method exists on the object, it will be called with the appropriate arguments.

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