In perl we can declare the array with qw
or quote word
take make each word is taken into individual array cell. eg.
my @arr= qw( hello
world)
or else you need to quote each word eg
my @arr = ("hello" , "word");
Is there something similar in javascript as sometime it need lot of formatting to simple declare array.
This is what you need, for this specific case: const arr = 'hello world'.split(' ');
.
Edit: Check out the docs for String.split
on MDN . Also, read something on types in JavaScript, if you are wondering why it is possible to call this method on string literal, as I did.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.