Array - splice
<html>
<body>
<script type="text/javascript">
myCars=["BMW","Volvo","Xiali","Jili"]
document.write("myCars: " + myCars)
document.write("<br><br>")
removed=myCars.splice(2,0,"Volkswagen")
document.write("After adding 1: " + myCars)
document.write("<br><br>")
removed=myCars.splice(3,1)
document.write("After removing 1: " + myCars)
document.write("<br><br>")
removed=myCars.splice(2,1,"Seat")
document.write("After replacing 1: " + myCars)
document.write("<br><br>")
removed=myCars.splice(0,2,"Peugeot","Honda","Toyota")
document.write("After replacing 2 and adding 1: " + myCars)
</script>
</body>
</html>
Related examples in the same category