LoginSignup
0
0

More than 5 years have passed since last update.

Reduce of empty array with no initial value

Last updated at Posted at 2019-04-07

demo https://codepen.io/gnjo/pen/XQjrqX?editors=1010

let a=[],b=['xxx'],c=['ee'],d=void 0
;
let ret=[].reduce((a,b)=>a.concat(b),[]) //safe
console.log(ret)
let ret2=[].reduce((a,b)=>a.concat(b)) //Reduce of empty array with no initial value
console.log(ret2)
let ret3=[a,b,c,d].reduce((a,b)=>a.concat(b))
console.log(ret3)
;//

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0