freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../basic-javascript/manipulate-arrays-with-shift/index.md

370 B
Raw Blame History

title localeTitle
Manipulate Arrays With shift() 使用shift操纵数组

使用shift操纵数组

虽然pop()用于删除数组的最后一个元素,但shift()用于删除第一个元素。这就像你将元素向下移动一个位置。看一下这个:

var arr = [1, 2, 3, 4, 5]; 
 arr.shift(); // Gets rid of the 1