I'm new to javascript and want to store (array) value from database in variable which I can manipulate later in my code. I'm using MongoDB and this is one example of the objects that are stored.
{
"_id": {
"$oid": "60a2247fcfe6fbbd6ce93ee0"
},
"project": ["4", "1"],
"title": "Test",
"url": "test",
"urlTitle": "test1",
"urlInstance": "https://www.google.com/",
"__v": 0
}
I want to store the project values in an array (x). I use this code.. I figure out that myFunction() in not returning anything that's why in the console I get "x=undefined". what should I change in the code so the function return the value of the project? Thank you in advance.
function myFunction() {
User.find({title: "Test"})
.then(
(myData) => {
var rez= myData[3].project;
return rez;
})
}
var x= new Array;
x= myFunction();
console.log ("x=" + x);