How can I convert a string into a math operator in javascript [duplicate]

var math_it_up = {
    '+': function (x, y) { return x + y },
    '-': function (x, y) { return x - y }
}​​​​​​​;

math_it_up['+'](1, 2) == 3;

Leave a Comment