what does results.push({}) nodejs mean
const mongoose = require('mongoose');
var data = async function () {
var array = [];
const finalResults = await new Promise((resolve, reject) => {
mongoose.connection.collection("organizations").find({}).toArray(function(err, result) {
resolve(result);
});
});
for(var i = 0; i < finalResults.length; i++)
{
var a = finalResults[i].name;
array.push(a);
}
return array;
};
module.exports = {
data: data,
};const mongoose = require('mongoose');
var data = async function () {
const array = await mongoose.connection.collection("organizations").find({}).toArray(function(err, result) {
if (err) throw err;
return result.map(r => r.name);
});
console.log(array); //this shows only [] meaning that the array is now empty.
//this is shown in the log before the first log
return array;
};
module.exports = {
data: data,
};
Also in JavaScript:
- get syntethicbaseevent and parameter in react
- how to start react project on atom
- get css value jquery
- array reverse algorithm in js
- javascript get age
- js string insert space
- how to remove key value pair from object in javascript
- js date in arabic
- react js build production
- javascript Count the frequency of a value in an array
- what are callbacks
- reverse keys and values in object javascript
- js array delete specific element
- class in react
- how to Check if an array contains a string
- nodejs sharp change image to multiple sizes
- convert an array of strings to numbers
- class javascript
- js change html lang
- let scores = [80, 90, 70]; for (const score of scores) { console.log(score); }
- js console.log color
- jquery is triggered on every element with class name
- .pop js
- angular cli skip-tests