.head and .tail
Gets the first element or all but the first element.
- const array = [1, 2, 3]
- // Underscore: _.first, _.head, _.take
- // Lodash: _.first, _.head
- _.head(array)
- // output: 1
- // Underscore: _.rest, _.tail, _.drop
- // Lodash: _.tail
- _.tail(array)
- // output: [2, 3]
- // Native
- const [ head, ...tail ] = array
- console.log(head)
- // output: 1
- console.log(tail)
- // output [2, 3]
Browser Support for Spread in array literals
46.0 ✔ | 12.0 ✔ | 16.0 ✔ | ✖ | 37.0 ✔ | 8.0 ✔ |
当前内容版权归 you-dont-need 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 you-dont-need .