I am fetching some json, but i want to add a key value pair to each object inside the array.
What i want is to add a key value pair to each object inside students array
You can do something like this:
var students = [ { city: 'California', company: 'ABC'}, { city: 'LA', company: 'PQR'}, { city: 'Mumbai', company: 'XYZ'}]; students.forEach((obj) => { obj['email']= '[email protected]'; console.log(obj); }); // Final Output console.log(students);
2.1m questions
2.1m answers
60 comments
57.0k users