Linked Questions
50 questions linked to/from Execute JavaScript code stored as a string
-4
votes
1
answer
666
views
How to execute javascript code from a ajax response? [duplicate]
I want to run javascript codes from ajax response. For example, I want to show the result via a modal. If I use eval() function, will there be any security issue?
0
votes
5
answers
228
views
How to execute JS statement from a string? [duplicate]
I wanna basically execute a statement stored in a var. For example, I have this,
var statement = "alert('Hi!')";
How can I make JS execute the statement stored inside the var statement? Thanks a lot ...
0
votes
0
answers
406
views
Convert string into function in Javascript or JQuery [duplicate]
In JS or Jquery, is it possible to convert a string into a function, and run it ?
Something like this :
var s = 'var n = 0; n++; alert(n)';
convertStringToFunction(s); // this would show an alert ...
-2
votes
5
answers
363
views
Execute JavaScript Code from String [duplicate]
Is there any 'code/function/algoritm' to convert the javascript string?:
var alert = "alert('Hello World!')";
In javascript syntax; in this case, it would display Hello World! on the screen.
-1
votes
2
answers
92
views
Execute a function when it is retrieved via a String [duplicate]
I have the situation that I retrieve a function in a string:
var function_name = "function Test(value){return value + 1}";
now I want to execute the function and store the value inside a variable so ...
-3
votes
1
answer
141
views
Is there anyway to execute JavaScript from a variable? [duplicate]
I'm trying to make a discord bot that executes syntax that we give in the server and send the console logs... How can I do that?
0
votes
1
answer
124
views
Is there a way to store JavaScript in a variable and run it? [duplicate]
I'm trying to make a function that runs a specified piece of code forever. How can I do this?
Example:
function forever(code) {
for (let i = 1; i > 0; i++) {
//Run code from variable here
...
0
votes
1
answer
107
views
How can I make an input where I can write javascript code which then can be saved in a script? [duplicate]
I want to have a textarea or an input where a user can write javascript code and save it (by clicking a button). Once the code is saved, it is inserted in a script and when the user clicks on "run" ...
0
votes
1
answer
96
views
How to change a string expression to an resulted integer? [duplicate]
Possible Duplicate:
How can I execute Javascript stored as a string?
Let us suppose this:
var a = 10;
var b = 20;
var exp = "a+b";
var result = ?;
Change the above expression which is string to ...
-2
votes
1
answer
76
views
Run JS code saved in a variable as string [duplicate]
I have a code saved in string. For eg:
const code = "res.send("Hi")";
How can I execute the above code in JS? I wanna execute the code of the code variable.
I can't just write code;...
0
votes
1
answer
77
views
Is it possible to store a function in form of an String and call it after calling the string? [duplicate]
To make it more clear, I will put what I want to do in code.
var functionsafe = "function plus(a,b){c=a+b; return c}";
and we can directly call function add ()= functionsafe;
I wonder if there is a ...
-1
votes
2
answers
38
views
Javascript chained scope and context [duplicate]
Is it possible to define a function run that acts like this?
a = run('var x = 100;')
b = run('console.log(x);') // prints 100
c = run('y = 1;')
d = run('console.log(y);') // prints 1
...
0
votes
0
answers
45
views
Why is my jquery condition check not working? [duplicate]
I am having a problem where my condition check seems to always be true in the checkConditions function.
Click the 'Enter Spins' button and 'Toggle Numberpad' button and add a number. It will display ...
0
votes
1
answer
42
views
Extract the array represented as a string [duplicate]
i have a string as below and i would like to extract the array between the quotes.
mystring = "['str1','str2']"
I tried it with eval and i do not want to use eval in my code. is there any ...
0
votes
0
answers
17
views
Is there any way to run a script as a string in JavaScript? [duplicate]
Is there any way to run a script as a string in JavaScript like this?
// core.jslib
mergeInto(LibraryManager.library, {
myCallback: function (str, arg) {
runScript(str, arg); // I want a ...