---
title: "splice(start,deleteCount,val1,val2,...)：从start位置开始删除deleteCount项"
author: "canfly2010"
date: "2009-07-09T11:10:35Z"
tags: []
slug: "splice-start-deletecount-val1-val2-start-deletecount"
draft: false
lastmod: "2009-07-09T11:10:35Z"
id: 422369
url: "https://canfly2010.iteye.com/blog/422369"
---

splice(start,deleteCount,val1,val2,...)：从start位置开始删除deleteCount项，并从该位置起插入val1,val2,...  
var a = \[1,2,3,4,5];  
var b = a.splice(2,2,7,8,9); //a：\[1,2,7,8,9,5]  b：\[3,4]  
var b = a.splice(0,1); //同shift  
a.splice(0,0,-2,-1); var b = a.length; //同unshift  
var b = a.splice(a.length-1,1); //同pop  
a.splice(a.length,0,6,7); var b = a.length; //同push