增加JavaScript的可读性

1.向数组添加最后一项

原生方法 

const list = []
const newList = [...list].push('last') // 为了不改变原数组

更加可读性的方法

const list = []
const newList = [...arr, 'last']

2.向数组添加第一项

原生方法

const list = []
const newList = [...list].unshift('first') // 为了不改变原数组

更加可读性的方法

const arr = []
const newArr = ['first', ...arr]

猜你喜欢

转载自blog.csdn.net/coderMozart/article/details/89538474
今日推荐