-1👍
The for...in
construct is not doing what you think here. It is is designed to iterate over objects. So in this case it is treating newArray
as an object but with the property names as the array indices. Arrays in Javascript are just objects with numeric property names. More specifically if you changed your code to:
for (let i in newarray) {
if (i.version.startsWith('iPad')) {
console.log(i);
}
}
You would clearly see the problem. i
is a number and not a job object.
-1👍
fix:
orderedUsers: function () {
let newarray = sortBy(this.jobs, 'version').reverse()
for (let i in newarray) {
if (newarray[i].version.startsWith('iPad')) {
console.log(newarray[i].version);
}
}
return newarray
- [Vuejs]-Laravel Image Validation
- [Vuejs]-How to make modal movable from one end to other end using vue js
Source:stackexchange.com