I have a problem with my carPassing
function. I'm trying to add a object literate into an array. Console log is a number instead of an array list. Why is that so? What am I doing wrong?
If the array is too big, does it just give the sum instead?
obtained:
4
expected:
[
{
time: 1568329654807,
speed: 40,
},
{
time: 1568329821632,
speed: 42,
},
{
time: 1568331115463,
speed: 35
},
{
time: 1568331115463,
speed: 38
}
]
Tried: Quick Google, splicing
, alternative inputs, printing
separately and unshift
.
Code:
const carPassing = function(cars, speed){
return cars.push({time: Date.now(), speed: speed});
}
const cars = [
{
time: 1568329654807,
speed: 40,
},
{
time: 1568329821632,
speed: 42,
},
{
time: 1568331115463,
speed: 35
}
]
const speed = 38
console.log(carPassing(cars, speed));