Iam a beginner and just starting with JS. Please forgive me if this is a stupid question.
After pushing a value into an array nested in an object. It shows the number of items in the array but the values are undefined rather than displaying the new array when i console log.
const warrior = {
health: 100,
equipment: ["sword", "sheild"],
location: {
x: 0,
y: 0,
},
walk: function(a, b) {
warrior.location.x = warrior.location.x + a;
warrior.location.y = warrior.location.y + b
},
strike: function(c) {
warrior.health = warrior.health - c
},
pickMeUp: function(equip) {
warrior.equipment = warrior.equipment.push(equip)
}
}
warrior.pickMeUp("axe");
console.log(warrior.equipment);
//undefined
//3
Im not sure why this is happening? Does this have anything to do with the way i wrote the function? writing it as >>
pickMeUp:function(equip){
this.equipment.push(equip)
removes - undefined
but, it still only returns array length and not the values.