rel1x
rel1x

Reputation: 2441

Check if observer contains some element

To check if array contains undefined I can do it like this [undefined].indexOf(undefined) or this [undefined].some(el => el === undefined). But in my Vue.js app I've got -1 and false. I tried to print my data and I've got [__ob__: Observer]. How to check if Observer contains undefined?

var app = new Vue({
  el: '#app',
  data: [undefined]
  },
  methods: {
    someFunction() {
      console.log(this.data.some(el => el === undefined), this.data.indexOf(undefined));
    }
  }
}) 

Upvotes: 3

Views: 2250

Answers (1)

str
str

Reputation: 44969

Vue.js expects data to be an object, not an array.

var app = new Vue({
  el: '#app',
  data: {
     prop: [undefined]
  },
  methods: {
    someFunction() {
      console.log(this.prop.some(el => el === undefined), this.prop.indexOf(undefined));
    }
  }
});

Upvotes: 2

Related Questions