Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > alt.comp.lang.javascript > #6 > unrolled thread
| Started by | $Bill <news@todbe.com> |
|---|---|
| First post | 2016-07-18 23:40 -0700 |
| Last post | 2017-05-18 20:13 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to alt.comp.lang.javascript
Any way to do this in JavaScript? $Bill <news@todbe.com> - 2016-07-18 23:40 -0700
Re: Any way to do this in JavaScript? kintalken@gmail.com - 2017-05-18 20:13 -0700
| From | $Bill <news@todbe.com> |
|---|---|
| Date | 2016-07-18 23:40 -0700 |
| Subject | Any way to do this in JavaScript? |
| Message-ID | <nmki0q$nl9$1@dont-email.me> |
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?
[toc] | [next] | [standalone]
| From | kintalken@gmail.com |
|---|---|
| Date | 2017-05-18 20:13 -0700 |
| Message-ID | <fca84d5d-c7e1-417a-a2a6-e1150dfaed06@googlegroups.com> |
| In reply to | #6 |
On Monday, July 18, 2016 at 11:40:28 PM UTC-7, $Bill wrote:
> In Perl, I have:
>
> my ($title, $chan, $call, $sTime, $dur) = split /~~/, $el;
$el = 'a~~b~~c~~d~~e' ;
[$title, $chan, $call, $sTime, $dur] = $el.split('~~') ;
console.log({title : $title , chan : $chan , call : $call , sTime : $sTime , dur : $dur}) ;
=>
{ title: 'a', chan: 'b', call: 'c', sTime: 'd', dur: 'e' }
.c.f. "deconstruction" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
~~ kintalken ~~
[toc] | [prev] | [standalone]
Back to top | Article view | alt.comp.lang.javascript
csiph-web