Append element to the end of an Array by reference the Array.length property in JavaScript

Description

The following code shows how to append element to the end of an Array by reference the Array.length property.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
<!--from   ww w . ja  v a 2s.  co m-->
var x = new Array(2,3,4);
x[x.length] = 1;
document.writeln(x);
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Append element to the end of an Array by reference the Array.length property in JavaScript
Home »
  Javascript Tutorial »
    Data Type »
      Array
...
Access the length of an array in JavaScript
Add items to the end of an array with the l...
Add items to the front of an array and retu...
Add undefined element to an array by settin...
Append element to the end of an Array by re...
Assign undefined value to an array element ...
Assign value to a Two-dimensional array in ...
Call array constructor without new operator...
Change array created with array literal in ...
Change array length with length property in...
Check each value in an array with some() fu...
Check if a variable is array type with Arra...
Check if a variable is array type with inst...
Check if array.sort is case sensitive in Ja...
Concatenate Array elements together in Java...
Concatenate two dimensional array in JavaSc...
Create a case-insensitive comparison in Jav...
Create an array with different type of valu...
Create an array without setting its length ...
Create an empty array with array literal in...
Create array with Array Constructor and set...
Create array with Array Constructor and set...
Create array with array literal notation in...
Create your own function for sorting in Jav...
Delete an array element in JavaScript
Delete with Array splice() in JavaScript
Display Multi-dimensional array in a HTML t...
Do an alphabetical sort() method on strings...
Fill and populate two dimensional array in ...
Filter an array with a condition in JavaScr...
Get a string of the array elements separate...
Get array element value with index in JavaS...
Get the last element in an Array in JavaScr...
Insert with Array splice() in JavaScript
Integer Array Declaration with initializati...
Join array elements together with string se...
Loop through an array with for statement in...
Loop through array and work on each element...
...