Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Object [object Array] has no method 'includes' with Ionic 3

I got this error when I try to execute the following code, I am using Ionic3 framework:

ERROR TypeError {stack: "TypeError: Object [object Array] has no method 'in… (http://192.168.0.25:8100/build/main.js:4116:76)", message: "Object [object Array] has no method 'includes'"}

enter image description here

// console.log(this.events) => [7704] 
// console.log(event.id_calenda) => 7653 
if (this.events.includes(event.id_calendar)) {

It happens in my device with Android 4.4.4, the other one with Android 7 works good, why?

like image 549
Otto Avatar asked Dec 05 '25 14:12

Otto


1 Answers

I fixed it using Array.prototype.indexOf() instead of Array.prototype.includes():

if (this.events.indexOf(event.id_calender) >= 0) {

Array.prototype.indexOf() documentation

Array.prototype.includes() documentation

like image 110
Otto Avatar answered Dec 08 '25 02:12

Otto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!