Separating an Array : Push « Array « JavaScript Tutorial






<html>
<head>
<title>Separating an Array</title>

</head>
<body>

<h1>Separating an Array</h1>

<script language="javascript" type="text/javascript">
<!--

var ages = new Array(12,57,32,6,21,19);
ages = ages.reverse();

var adults = new Array();
var minors = new Array();

while (ages.length) {
  var tempAge = ages.pop();
  if (tempAge < 21)
     minors.push(tempAge);
  else
     adults.push(tempAge);
}

alert(minors);
alert(adults);

//-->
</script>

</body>
</html>








11.22.Push
11.22.1.Array.push()
11.22.2.Separating an Array
11.22.3.Using push method from zArray Library