silentmatt / expr-eval

Mathematical expression evaluator in JavaScript
http://silentmatt.com/javascript-expression-evaluator/
MIT License
1.19k stars 239 forks source link

how to use And ? I mean multi expression #188

Closed JesterCheung closed 5 years ago

JesterCheung commented 5 years ago

sometimes like : parIn.evaluate('3 in array and 3 in "%str%"', { array: [ 1, 2, 3 ],str:"123" }))

silentmatt commented 5 years ago

The in operator uses the strict equality operator (===), so the types need to match. Your usage of and is fine, but the right side should be "3" in str. For reference, here's a complete example that should do what you expect:

var parIn = new Parser({ operators: { 'in': true } });
parIn.evaluate('3 in array and "3" in str', { array: [ 1, 2, 3 ], str: "123" });