js array oush code example
Example 1: how to push items in array in javascript
let items = [1, 2, 3]
items.push(4);
Example 2: javascript array clear
var cars = ["mazda","honda","tesla"];
cars = [];
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,
};
Example 4: js push
let arr = [9, 4, 3, 18]
arr.push(30)
console.log(arr)
Example 5: push javascript
let twentyThree = 'XXIII';
let romanNumerals = ['XXI', 'XXII'];
romanNumerals.push(twentyThree);
romanNumerals.unshift('XIX', 'XX');