Клиентский JavaScript. Справочник

         

Пример


Следующий скрипт иллюстрирует использование splice:

<SCRIPT LANGUAGE="JavaScript1.2"> myFish = ["angel", "clown", "mandarin", "surgeon"];
document.writeln("myFish: " + myFish + "<BR>"); removed = myFish.splice(2, 0, "drum");
document.writeln("After adding 1: " + myFish);
document.writeln("removed is: " + removed + "<BR>"); removed = myFish.splice(3, 1)
document.writeln("After removing 1: " + myFish);
document.writeln("removed is: " + removed + "<BR>"); removed = myFish.splice(2, 1, "trumpet")
document.writeln("After replacing 1: " + myFish);
document.writeln("removed is: " + removed + "<BR>"); removed = myFish.splice(0, 2, "parrot", "anemone", "blue")
document.writeln("After replacing 2: " + myFish);
document.writeln("removed is: " + removed); </SCRIPT>

Этот скрипт выведет:

myFish: ["angel", "clown", "mandarin", "surgeon"] After adding 1: ["angel", "clown", "drum", "mandarin", "surgeon"]
removed is: undefinedAfter removing 1: ["angel", "clown", "drum", "surgeon"]
removed is: mandarinAfter replacing 1: ["angel", "clown", "trumpet", "surgeon"]
removed is: drumAfter replacing 2: ["parrot", "anemone", "blue", "trumpet", "surgeon"]
removed is: ["angel", "clown"]



Содержание раздела