Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30901
| From | Martin Honnen <martin.honnen@gmx.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Any way to do this in JavaScript? |
| Date | 2016-07-19 20:14 +0200 |
| Organization | Liberty Development |
| Message-ID | <nmlqm3$gms$1@news.albasani.net> (permalink) |
| References | <nmln2h$kbr$1@dont-email.me> |
On 19.07.2016 19:12, $Bill wrote:
> Sent this to alt... by mistake - let's try here.
>
> In Perl, I have:
>
> my ($title, $chan, $call, $sTime, $dur) = split /~~/, $el;
>
> I've converted this to JavaScript thusly:
>
> var flds = el.split('~~'); // split into array, then to vars
>
> var title = flds[0];
> var chan = flds[1];
> var call = flds[2];
> var sTime = flds[3];
> var dur = flds[4];
>
> I was hoping for a more straightforward/cleaner syntax - something like:
>
> var (title, chan, call, sTime, dur) = el.split('~~'); // do it all
> in one like Perl
>
> Any way to do that?
See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment,
in Firefox and Chrome you should be able to use e.g.
var [title, chan, call, sTime, dur] = el.split('~~');
See https://jsfiddle.net/rxjwajpn/.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Any way to do this in JavaScript? $Bill <news@todbe.com> - 2016-07-19 10:12 -0700
Re: Any way to do this in JavaScript? Martin Honnen <martin.honnen@gmx.de> - 2016-07-19 20:14 +0200
Re: Any way to do this in JavaScript? $Bill <news@todbe.com> - 2016-07-19 12:02 -0700
Re: Any way to do this in JavaScript? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-07-19 21:05 +0200
Re: Any way to do this in JavaScript? $Bill <news@todbe.com> - 2016-07-19 12:49 -0700
Splitting strings (was: Any way to do this in JavaScript?) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-07-20 00:25 +0200
Re: Splitting strings (was: Any way to do this in JavaScript?) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-07-20 09:45 +0200
Re: Any way to do this in JavaScript? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-07-19 23:21 -0700
Re: Any way to do this in JavaScript? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-07-20 10:56 +0200
csiph-web