Does JavaScript support array/list comprehensions like Python? -
i'm practicing/studying both javascript , python. i'm wondering if javascript has equivalence type of coding.
i'm trying array each individual integer string practice purposes. i'm more proficient in python javascript
python:
string = '1234-5' forbidden = '-' print([int(i) in str(string) if not in forbidden])
does javascript have similar me above?
yes, javascript support array comprehensions in upcoming ecmascript version 7: https://developer.mozilla.org/en-us/docs/web/javascript/reference/operators/array_comprehensions.
here's example: array comprehensions.
var str = "1234-5"; var ignore = "-"; console.log([for (i of str) if (!ignore.includes(i)) i]);
Comments
Post a Comment