0

Undefined Error in array.push after putting it in a variable then printing the value in the variable it in console

I am getting an undefined error when I make a new variable in JS and gave it the value array.push() and when i try to print the value of that variable in console.log(variable), I get an undefined error. Please help me and if possible explain to me as to why I am getting this. https://code.sololearn.com/W1NAxMElpbEM Thanks in Advance.

14th Nov 2021, 11:27 AM
Manvendra Rajpoot
Manvendra Rajpoot - avatar
2 Réponses
0
push() returns the size of <prices> after you push a new item into it. The value (array size) returned is of a number type, which doesn't have a `length` property. Hence 'undefined' with your attempt to log price1.length
14th Nov 2021, 12:02 PM
Ipang
+ 1
Thanks 😊
14th Nov 2021, 12:55 PM
Manvendra Rajpoot
Manvendra Rajpoot - avatar