I am a newbie in JavaScript and AngularJS. I was trying out looping a object, get its key-value pair and then use it to build an array of new objects.
var actorMovie = { "Leonardo DiCaprio" : "The Revenant", "Christian Bale" : "The Dark Knight Rises", "Sylvester Stallone" : "Rocky" }; if(actorMovie){ var actorMovieArray = []; angular.forEach(actorMovie, function(value, key) { actorMovieArray.push ({key: { "Movies": { "Best Movie": value } }}); }); } console.log(actorMovieArray);
This console log prints out the right values, but the key remains as 'key' and never updated to the actor's name as expected. What am I doing wrong here? I tried searching for an answer but did not find any solution. Am I missing something?