Ask Your Question
0

Is it not possible to output an array in a function in Javascript?

asked 2022-02-07 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-06 13:00:00 +0000

nofretete gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-07 11:00:00 +0000

Seen: 8 times

Last updated: Aug 06 '21