1 | initial version |
It is possible to output an array from a function in Javascript. A function can return a value which can be an array. Here's an example:
function getArray() {
var arr = [1, 2, 3, 4, 5];
return arr;
}
var myArray = getArray();
console.log(myArray); // Output: [1, 2, 3, 4, 5]
In this example, the function getArray()
returns an array [1, 2, 3, 4, 5]
. The returned array is stored in a variable myArray
, which can be used later. The console.log()
statement prints the array to the console.