2

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?

3
  • 2
    Probably because the Browser on your old device only supports an older version of EcmaScript Commented Feb 12, 2018 at 23:32
  • 1
    Agreed, the older browsers don't support .includes. You'll need to use a polyfill for it to work on those older browsers. Commented Feb 12, 2018 at 23:37
  • 1
    check out polyfill.io Commented Feb 13, 2018 at 11:25

2 Answers 2

9

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

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

1 Comment

indexOf counts from 0, so will return 0 if the item is first in the array. indexOf returns -1 if the item is not in the array. So the code should be changed to: if (this.events.indexOf(event.id_calender) >= 0) {
4

I have the same error on Android 4.4.2, but it's needed to use >= operator to replace Array.prototype.includes() method:

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

Comments

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.