var arrOfObj = [{name: 'eve'},{name:'john'},{name:'jane'}];var injectObj = {isActive:true, timestamp:new Date()};
// function to inject key values in all object of json array
function injectKeyValueInArray (array, keyValues){return new Promise((resolve, reject) => {if (!array.length)return resolve(array);
array.forEach((object) => {for (let key in keyValues) {object[key] = keyValues[key]}});resolve(array);})};
//call function to inject json key value in all array objectinjectKeyValueInArray(arrOfObj,injectObj).then((newArrOfObj)=>{console.log(newArrOfObj);});
let my_object = {};
// now i want to add something in it
my_object.red = "this is red color";
// { red : "this is red color"}
例2
let my_object = { inside_object : { car : "maruti" }}
// now i want to add something inside object of my object
my_object.inside_object.plane = "JetKing";
// { inside_object : { car : "maruti" , plane : "JetKing"} }
例3
let my_object = { inside_object : { name : "abhishek" }}
// now i want to add something inside object with new keys birth , gender
my_object.inside_object.birth = "8 Aug";my_object.inside_object.gender = "Male";
// { inside_object :// { name : "abhishek",// birth : "8 Aug",// gender : "Male"// }// }