I am trying to return an array of numbers in a Javascript function.
function getSeasons() {
db.any('select season from video', [true]) //recieving unsorted data
.then(function (data) {
let sorted = new SortedSet(); // creating SortedSet from collections.js
data.forEach(function (item) {
sorted.push(item.season) // fills set with data
});
console.log(sorted.toArray()) // works fine
})
.catch(function (error) {
console.log(error)
})
}
}
That console.log(sorted.toArray())
works fine and in a console I recieve log like [1, 2, 3, 4, 5]. But if I'm trying to make return sorted.toArray()
- result of it is undefined
. Why?
The question is if we have something like ( this is a simplified version of the code above)...
function getArray() {
var array = [1, 2, 3];
//return ??
}
...how to get this [1, 2, 3]
using getArray()
?