javascript - What's the equivalent of a list comprehension like this one in ES2016 or greater? -


python 3.6:

[f"cat #{n}" n in range(5)]

gives

['cat #0', 'cat #1', 'cat #2', 'cat #3', 'cat #4']

new javascript, what's equivalent in new ecmascript?

array comprehension in js proposed es2016, never made final release. firefox supported comprehensions time, support dropped in later versions.

you can use array#from close comprehension.

const result = array.from({ length: 5 }, (_, k) => `cat #${k}`);    console.log(result);


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -