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.

  • 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? – Bert Feb 16 '17 at 16:36
  • @BertEvans Yes Correct .. do you have any idea? Thanks. – Syafrizal Natawiria Feb 17 '17 at 01:40
  • Does this answer your question? [Check if value exists in vuejs](https://stackoverflow.com/questions/35787159/check-if-value-exists-in-vuejs) – showdev Mar 23 '22 at 02:06

1 Answers1

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.

Young Kim
  • 31
  • 4
  • @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 :

    {{r}}
    /p> I want the result like bellow :

    Jhon
    Doe

    Foo
    Bar
    If keys in rows = id and remarks, they not print on template
    – Syafrizal Natawiria Feb 17 '17 at 04:24
  • Here's jsfiddle of what I think you are looking for [https://jsfiddle.net/rzsxo7ra/1/](https://jsfiddle.net/rzsxo7ra/1/) – Young Kim Feb 17 '17 at 04:34
  • 1
    Thanks for your reply, i found solution from this http://stackoverflow.com/questions/35787159/check-if-value-exists-in-vuejs – Syafrizal Natawiria Feb 17 '17 at 09:49