0

I have object like this:

data() {
    return {
         headings: ['id','remark'],
         rows: [
            {
              id: 1,
              FirstName: 'Jhon',
              LastName: 'Doe',
              remark: 0
           },
           {
              id: 2,
              FirstName: 'Foo',
              LastName: 'Bar',
              remark: 1
           }
         ]
    }}

Is there away how do i check if key headings object exist in rows object.

Thanks and sorry for my bad english.

3
  • I'm trying to understand what you mean. Do you mean you want to know if each of the properties specified in your headings array exists on the objects in the rows array? Commented Feb 16, 2017 at 16:36
  • @BertEvans Yes Correct .. do you have any idea? Thanks. Commented Feb 17, 2017 at 1:40
  • Does this answer your question? Check if value exists in vuejs Commented Mar 23, 2022 at 2:06

1 Answer 1

0

Yes, There's a way

function (row) {
   return this.headings.reduce((res, heading) => res &= row.hasOwnProperty(heading), true)
}

This method should return true - if the row has the heading.

Sign up to request clarification or add additional context in comments.

3 Comments

@yong-kim, thanks for your suggestion. I was tried your suggestion. On filters i've make function like this : filters: inArray: function(row) { return this.headings.reduce((res, heading) => res &= row.hasOwnProperty(heading), true) } on my own template like this : <p v-for="r in rows"><div v-for="r in row" v-if="r | inArray">{{r}}</div>/p> I want the result like bellow : <p><div>Jhon</div><div>Doe</div></p><p><div>Foo</div><div>Bar</div></p> If keys in rows = id and remarks, they not print on template
Here's jsfiddle of what I think you are looking for https://jsfiddle.net/rzsxo7ra/1/
Thanks for your reply, i found solution from this stackoverflow.com/questions/35787159/…

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.