remove first element from array and return the array minus the first element

后端 未结 5 1421
温柔的废话
温柔的废话 2021-01-31 01:09



        
5条回答
  •  春和景丽
    2021-01-31 01:29

    This should remove the first element, and then you can return the remaining:

    var myarray = ["item 1", "item 2", "item 3", "item 4"];
        
    myarray.shift();
    alert(myarray);

    As others have suggested, you could also use slice(1);

    var myarray = ["item 1", "item 2", "item 3", "item 4"];
      
    alert(myarray.slice(1));

提交回复
热议问题