I want to evaluate a dynamically created string inside a map function. This is how it should work:
ar arr = [1,2,3,4,5];
var arr2 = arr.map(v=>((v+5)*6)); //Gives [36, 42, 48, 54, 60]
I have created a string as below:
var s = '((v+5)*6)';
var arr2 = arr.map(v=>eval(s)); // I need something like this to work!
Can you do two things please?
- Show how this can be done using eval on the string I have created (or an amended string).
- Suggest another (better) method of doing this - I'm sure there is one.
- Don't just skip out point 1)
Thanks
evalis necessary?evalsolution still works. Point2: You should provide more context to get help.