function show_array(arr)
{
for (var i = 0; i < arr.length; i++ )
{
document.write(array[i]);
document.write('<br/>');
}
}
var arr1 = [1, 2, 3];
show_array(arr1);
Array Properties | Description |
---|---|
Constructor | It returns a reference to the array function that created the object. |
Index | It represents the zero-based index of the match in the string. |
Length | It reflects the number of elements in an array. |
Input | It presents only an array created by regular expression matches. |
Prototype | It allows you to add properties and methods to an object. |
Methods | Description |
---|---|
concat() | It returns a new array comprised of this array joined with other arrays and values. |
every() | It returns true if every element in this array satisfies the provided testing function. |
filter() | It creates a new array with all the elements of this array for which the provided filtering function returns true. |
indexOf() | It returns the first index of an element within the array equal to the specified value. |
join() | It joins all elements of an array into a string. |
pop() | It removes the last element from an array and returns that element. |
push() | It adds one or more elements to the end of an array and returns the new length of the array. |
reverse() | It reverses the order of the elements of an array. |
sort() | It represents the source code of an object. |
<html>
<body>
<button onclick="arrpop();">POP</button>
<button onclick="arrpush();"> PUSH </button>
<script>
function arrpop()
{
var numbers = ["1", "2", "3", "4", "5", "ABC"];
document.write(numbers.pop()+" "+"Removed"+"<br>");
//pop() removes the last element of an array
// Now we have [1,2,3,4,5]
document.write("Now length is: "+numbers.length); // ABC removed
}
function arrpush()
{
var numbers = ["1","2","3","4","5","6"]
numbers.push("7");
// now we got ["1","2","3","4","5","6"]
document.write("Added element is :"+" "+numbers[numbers.length-1])
// Now we have [1,2,3,4,5,6]
document.write("<br>"+"Now length is: "+numbers.length); // 7 Added
}
</script>
</body>
</html>