I've got a very basic array:
specialityTest: [{person:'nurse', text:'text1'},
{person:'nurse', text:'text1'},
{person:'physician', text:'text1'},
{person:'physician', text:'text1'}]
I'm trying to filter this using basic filter function:
this.specialityTest.filter((person) => {
return (person =="physician")
})
and then copy filtered array:
methods: {
seedSpeciality(){
this.nurseListSpeciality2 = JSON.parse(JSON.stringify(this.specialityTest.filter(
(person) => {
return (person =="physician")
})))
},
}
and this is not working for me... I've got error:
Uncaught (in promise) TypeError: this.specialityTest.filter is not a function
at VueComponent.seedSpeciality (AddOfferDialog.vue?f4fc:1771)
at VueComponent.boundFn [as seedSpeciality].
What am I doing wrong here?
edit: I run this function from api call:
fetchSpecialityArray(){
this.$http.get('http://127.0.0.1:8000/api/speciality')
.then(response => response.json())
.then(result => this.specialityTest = result).then(this.seedSpeciality.bind(this))
},
console.log(this.specialityTest)to see if it's what you expect (may beundefined). Also, your filter condition should beperson.person === "physician"console.log(this.specialityTest)gives the correct array of 90 elements. changing filter conditions toperson.personis not changing the errorthismay not be correctly binding and you may need to explicitly bind the value. Alternatively, you can storethisinside a variable accessible via closure and then use that variable instead.