How come I am getting NaN instead of "qwe" and "qweqweqwe" when trying to push the first 6 elements from an array of objects to a new array?
Imagine the array of objects retrieved from the API is structured like this:
0: {id: 340, name: "qwe", lastname: "qweqweqweq", …}
1: {id: 341, name: "qwe", lastname: "qweqweqweq", …}
2: {id: 342, name: "qwe", lastname: "qweqweqweq", …}
3: {id: 343, name: "qwe", lastname: "qweqweqweq", …}
4: {id: 344, name: "qwe", lastname: "qweqweqweq", …}
5: {id: 345, name: "qwe", lastname: "qweqweqweq", …}
6: {id: 346, name: "qwe", lastname: "qweqweqweq", …}
7: {id: 347, name: "qwe", lastname: "qweqweqweq", …}
8: {id: 348, name: "qwe", lastname: "qweqweqweq", …}
This is how my code is currently implemented:
.then(response => {
console.log(typeof response.data, response.data);
this.model = {
name: response.data.name,
lastname: response.data.lastname
}
this.userInfo.unshift(this.model.name + this.model.lastname); // The issue seems to be here
if(this.userInfo.length > 6)
this.userInfo.pop();
})
.catch(error => {
console.log('An error occurred', error);
});
},