javascript push two values into array code example
Example 1: js array push
const arr = ["foo", "bar"];
arr.push('baz'); // 3
arr; // ["foo", "bar", "baz"]
Example 2: what does results.push({}) nodejs mean
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,
};
Example 3: js push multiple arguments
var a = [];
a.push(1, 2, 3);
console.log(a);
Example 4: javascript add multiple items to array
var a = [];
a.push(1, 2, 3);
console.log(a);