nodejs list push code example
Example 1: js array push
const arr = ["foo", "bar"];
arr.push('baz');
arr;
Example 2: .push js
let monTableau2D = [
['Mark' , 'jeff' , 'Bill'] ,
['Zuckerberg' , 'Bezos' , 'Gates']
] ;
monTableau2D[1].push('test') ;
console.log(monTableau2D) ;
let monTableau = ['un', 'deux','trois', 'quatre'] ;
monTableau.push('cinq') ;
console.log(monTableau) ;
let monTableauAssociatif = {
'prenom' : 'Mark' ,
'nom' : 'Zuckerberg' ,
'poste' : 'Pdg de Facebook',
} ;
monTableauAssociatif['nationalite'] = 'Américaine' ;
console.log(monTableauAssociatif) ;
Example 3: 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,
};