Javascript Data Type How to - Pass an array in the parameters of a function








Question

We would like to know how to pass an array in the parameters of a function.

Answer


<!--from  w w w .  j ava 2 s  .co  m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>

function someFunction(x){
    for(i=0;i<x.length;i++) {
      document.body.outerHTML += x[i];
    }
}
someFunction(['one ', 'two ', 'three']);

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

The code above is rendered as follows: