0

In my Vuejs below I want to filter the reviewed:true only questions, and get the length of them, but my code below gives an error TypeError: question.reviewed.includes is not a function ,is there a way to do it?

Here is the screenshot about the json file: JSON File

 filterReviewed() {
      return this.questions.filter((question) => {
        return (
            question.reviewed
            .includes('true')
        );
      });
    },

2
  • It seems reviewed is a property of question. return this.questions.filter((question) => question.reviewed). No need for includes. Commented Jan 23, 2021 at 22:29
  • Review is not a string property instead it is a boolean property. Try it as return this.questions.filter((question) => question.reviewed) Commented Jan 24, 2021 at 0:36

2 Answers 2

1

includes is a method of Object of Array type. Directly judge attribute reviewed is OK

filterReviewed (){
  return this.questions.filter((question) => question.reviewed);
}
Sign up to request clarification or add additional context in comments.

Comments

0

To filter the reviews try this:

filterReviewed() {
          return this.questions.filter((question) => question.reviewed === true);
        },

To get the filterReviewed length try this:

filterReviewed.questions.length

3 Comments

i tried your answer the filter works properly but i apply the length condition here it's not working ` <div class="showmore-Div" v-show=" commentsToShow < filterReviewed.length|| filterReviewed.length > commentsToShow " > <button @click="commentsToShow += 10" class="showMore-Button"> show more </button> </div>`
* commentsToShow: 25,
If you try this? filterReviewed.questions.length. ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.