js inserts content at the specified position in the array

Adds an element at the second-to-last position of the array

//例如在arr的倒数第二位插入字符串'c'
//splice(index值,删除的个数(当值为0时不删除),增加的内容)
 
 
let arr=['a','b','d']
arr.splice(-1,0,'c')
console.log(arr)    //'a','b','c','d'

Guess you like

Origin blog.csdn.net/qq_46617584/article/details/129983313