我有一个数组fruits = ['apple','mango','eggs','guvava','... many others']
。我有一个索引15
,所以我目前正在将元素作为fruits[14]
。
我有什么方法可以使用.splice / .slice
或任何ES6
方法做同样的事情。
我试过.slice(14,1)但没有得到理想的结果。
答案 0 :(得分:2)
fruits.slice(14,15)[0] // => get you the value of fruits[14] and allocate new memory for a new array
fruits.splice(14,1)[0] // => get you fruits[14] but mutates fruits array and also allocate new memory for a new array