Javascript Data Type How to - Return second value from multiple arrays








Question

We would like to know how to return second value from multiple arrays.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from  w  w  w  .j a va2s .co m-->
var arr = [
    ['2009', 1000, 400, 800],
    ['2010', 1170, 460, 1200],
    ['2011', 660, 1120, 500],
    ['2012', 1030, 540, 800]
];
var newArr = [];
for (var x = 0; x < arr.length; x++){
  newArr.push(arr[x][1]);
}
document.writeln(newArr);

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: