Informatika - JavaScript - metody pole

Deklarace a výpis prvků pole

<script type="text/javascript">
var i;
var tyden = new Array();
tyden[0] = "neděle";
tyden[1] = "pondělí";
tyden[2] = "úterý";
tyden[3] = "středa";
tyden[4] = "čtvrtek";
tyden[5] = "pátek";
tyden[6] = "sobota";

for (i=0;i<tyden.length;i++)
{
document.write(tyden[i] + "<br />");
}
</script>
nebo:
<script type="text/javascript">
var i;
var tyden=new Array("neděle","pondělí","úterý","středa","čtvrtek","pátek","sobota");

for (i=0;i<tyden.length;i++)
{
document.write(tyden[i] + "<br />");
}
</script>
nebo:
<script type="text/javascript">
var i;
var tyden=["neděle","pondělí","úterý","středa","čtvrtek","pátek","sobota"];

for (i=0;i<tyden.length;i++)
{
document.write(tyden[i] + "<br />");
}
</script>

concat()

<script type="text/javascript">

var rodice = ["mama", "tata"];
var deti = ["Lasse", "Bosse"];
var rodina = rodice.concat(deti);
  document.write(rodina);
</script>

join()

<script type="text/javascript">
var rodice = ["mama", "tata"];
var deti = ["Lasse", "Bosse"];
  document.write(rodice.join() + "<br />");
  document.write(rodice.join("+") + "<br />");
  document.write(rodice.join(" a "));
</script>

push()

<script type="text/javascript">
var rodice = ["mama", "tata"];
var deti = ["Lasse", "Bosse"];
  document.write(deti.push("Lisa") + "<br />");
  document.write(deti.push("Anna","Britta") + "<br />");
  document.write(deti);
</script>

reverse()

<script type="text/javascript">
var rodice = ["mama", "tata"];
var deti = ["Lasse", "Bosse", "Lisa"];
  document.write(deti.reverse());
</script>

shift()

<script type="text/javascript">
var deti = ["Lasse", "Bosse", "Lisa"];
  document.write(deti.shift() + "<br />");
  document.write(deti + "<br />");
  document.write(deti.shift() + "<br />");
  document.write(deti);
</script>

slice()

<script type="text/javascript">
var deti = ["Lasse", "Bosse", "Lisa", "Anna", "Britta"];
  document.write(deti.slice(0,2) + "<br />");
  document.write(deti.slice(1) + "<br />");
  document.write(deti.slice(-2) + "<br />");
  document.write(deti);
</script>

sort()

<script type="text/javascript">
var deti = ["Lasse", "Bosse", "Lisa", "Anna", "Britta"];
  document.write(deti.sort());
</script>

splice()

<script type="text/javascript">
var deti = ["Lasse", "Bosse", "Lisa", "Anna", "Britta"];
  document.write("Přidáno: " + deti.splice(2,0,"Kerstin") + "<br />");
  document.write(deti);
</script> 

toString()

<script type="text/javascript">
var deti = ["Lasse", "Bosse", "Lisa", "Anna", "Britta"];
  document.write(deti.toString());
</script>

unshift()

<script type="text/javascript">
var deti = ["Lasse", "Bosse", "Lisa", "Anna", "Britta"];
  document.write(deti.unshift("Olle") + "<br />");
  document.write(deti.unshift("Kerstin","Svipp") + "<br />");
  document.write(deti);
</script>

valueOf()

<script type="text/javascript">
var deti = ["Lasse", "Bosse", "Lisa", "Anna", "Britta"];
  document.write(deti.valueOf());
</script> 

GJK, Hanka Šandová, JavaScript