子陣列
slice()
方法會回傳一個新陣列物件,為原陣列選擇之 begin
至 end
(不含end)部分的淺拷貝(shallow copy)。而原本的陣列將不會被修改。
- 如果有設定end,就不含end
slice
creates a new array,newCar
, frommyCar
. When the color of is changed to black, both arrays reflect the change.var myCar = [{ color: 'red'} , 2, 'cherry condition']; var newCar = myCar.slice(0, 2); console.log(newCar) myCar[0].color = "black" console.log(newCar)