Array Overview

[Total: 0    Average: 0/5]

Array has 3 ways to create a new object:

Body Code:

<script type=text/javascript>
var a = new Array("one","two","three","four");
document.write(a+"<BR>");
a = a.concat("five","six");
document.write(a+"<BR>");
var s = a.join("*");
document.write(s+"<BR>");
document.write(a.length+"<BR>");
if (!document.all) {
  a.pop();
  document.write(a+"<BR>");
  a.push("seven");
  document.write(a+"<BR>");
}
a.reverse();
document.write(a+"<BR>");
if (!document.all) {
  s = a.shift();
  document.write(s+"<BR>");
}
s = a.slice(2,4);
document.write(s+"<BR>");
a = a.sort();
document.write(a+"<BR>");
function myX(a,b) {
  return (-1);
}
a = a.sort(myX);
document.write(a+"<BR>");
if (!document.all) {
  a = a.splice(1,1,"eight");
  document.write(a+"<BR>");
}
document.write(a.toString()+"<BR>");
if (!document.all) {
  document.write(a.unshift("nine"));
}
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *