Re:Flatten Arrays in Vanilla JavaScript with Flat() and Flat...
by eyelidlessness on Wednesday January 05, 2022 @08:08PM
(#29817720)
Comma operator to the rescue:
(acc.push(2*n), acc)
In an expression position, the push statement will be executed, then its return will be discarded, and the final expression will be the result of the expression. Is it “better”? Almost certainly not. But it lets you stay in expression syntax while executing statements. (Much more useful for logging than meaningful runtime side effects IMO, but I think it should be more widely known in general.)
Edit: and I’m glad to see another reference to it down thread!
Edit: and I’m glad to see another reference to it down thread!