Sunday, 29 July 2018

Javascript : Properties & method

Properties and Methods
The Array object has many properties and methods which help developers to handle arrays easily and efficiently. You can get the value of a property by specifying arrayname.property and the output of a method by specifying arrayname.method().
  1. length property --> If you want to know the number of elements in an array, you can use the length property.
  2. prototype property --> If you want to add new properties and methods, you can use the prototype property.
  3. reverse method --> You can reverse the order of items in an array using reverse method.
  4. sort method --> You can sort the items in an array using sort method.
  5. pop method --> You can remove the last item of an array using pop method.
  6. shift method --> You can remove the first item of an array using shift method.
  7. push method --> You can add a value as the last item of array.

<html>
<head>
 <title>Arrays!!!</title>
 <script type="text/javascript">
  var students = new Array("John", "Ann", "Aaron", "Edwin", "Elizabeth");
  Array.prototype.displayItems=function(){
   for (i=0;i<this.length;i++){
    document.write(this[i] + "<br />");
   }
  } 
  document.write("students array<br />");
  students.displayItems();
  document.write("<br />The number of items in students array is " + students.length + "<br />");
  document.write("<br />The SORTED students array<br />");
  students.sort();
  students.displayItems();
  document.write("<br />The REVERSED students array<br />");
  students.reverse();
  students.displayItems();
  document.write("<br />THE students array after REMOVING the LAST item<br />");
  students.pop();
  students.displayItems();
        document.write("<br />THE students array after PUSH<br />");
        students.push("New Stuff");
  students.displayItems();
 </script>
</head>
<body>
</body>
</html>
https://www.guru99.com/learn-arrays-in-javascript.html

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...