Javascript Passing an Array as a Function Parameter
Learn using Javascript passing an array as a function parameter
Published
- Javascript Passing an Array as a Function Parameter
- Example Passing an Array as a Function Parameter
Javascript Passing an Array as a Function Parameter
If you are passing multiple argument of similar type into a function this will not easy to maintain. Instead of passing individually you can pass them into an array. In this case array makes our life easier because it’s easy to maintain.
Example Passing an Array as a Function Parameter
<script>
var x = [ 'val-1', 'val-2', 'val-3' ];
call_Array(x);
function call_Array(params) {
for (i=0; i<params.length; i++) {
console.log(params[i])
}
}
</script>