返回第一个非空/未定义参数。
使用Array.find()
返回第一个非null
/undefined
的参数。
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_))
// coalesce(null,undefined,"",NaN, "Waldo") -> ""
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8