Answer the question
In order to leave comments, you need to log in
How to sort by id in Javascript?
Hello. There is such a code
computed: {
sortedPosts() {
return [...this.posts].sort((post1, post2) => post1[this.selectedSort]?.localeCompare(post2[this.selectedSort]))
},
}
((post1, post2) => post1.id - post2.id)
computed: {
sortedPosts() {
return [...this.posts].sort((post1, post2) => post1[this.selectedSort]?.localeCompare(post2[this.selectedSort])?.(post1, post2) => post1.id - post2.id)
}
}
computed: {
sortedPosts() {
return [...this.posts].sort((post1, post2) => post1[this.selectedSort]?.localeCompare(post2[this.selectedSort]):post1.id - post2.id)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question