Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 380 Bytes

castArray.md

File metadata and controls

17 lines (13 loc) · 380 Bytes
方法名 标签
castArray
类型,数组,初级

如果提供的值不是数组,则将它转为数组。

  • 使用 Array.prototype.isArray() 来确定 val 是否为数组,并按原样返回或相应地封装在数组中。
const castArray = val => (Array.isArray(val) ? val : [val]);
castArray('foo'); // ['foo']
castArray([1]); // [1]