Ionic3中Object [object Array]无includes方法报错问题咨询
问题原因与解决方案
Hey there, let's break down why this error hits only on Android 4.4.4 and how to fix it!
核心原因
The key issue here is WebView version compatibility:
- Android 4.4.4 comes with an outdated WebView kernel (roughly based on Chrome 30), and
Array.prototype.includes()is an ES2016 (ES7) feature. This old WebView doesn't support this modern API at all, which is exactly why you see the "has no method 'includes'" error. - Android 7, by contrast, ships with a much newer WebView that fully supports modern ES features, so your code runs smoothly there.
可行的解决方案
1. 用兼容写法替换includes()
The simplest fix is to swap out includes() with the widely supported indexOf() method. For example:
- Instead of:
if (myArray.includes(myItem)) { ... } - Use:
if (myArray.indexOf(myItem) !== -1) { ... }
This works across all older browsers and WebViews, including Android 4.4.4's.
2. 添加Polyfill补全缺失的API
If you want to keep using includes() in your code, you can add a polyfill to make the method available in older environments:
- If
core-jsisn't already in your project (it's usually included in Ionic/Angular setups by default), install it first:npm install core-js --save - Then, add this import at the very top of your
src/main.tsfile:import 'core-js/es7/array';
This will inject the polyfill for Array.prototype.includes() and make it work in Android 4.4.4's WebView.
3. 确认编译配置的ES5转译设置
Double-check your project's build config to ensure it's targeting ES5, which is compatible with older WebViews:
- Open
tsconfig.jsonand make sure thetargetproperty is set to"es5":{ "compilerOptions": { "target": "es5", ... } } - For older Ionic versions, verify that your build pipeline is configured to transpile modern JavaScript to ES5.
内容的提问来源于stack exchange,提问作者Otto
相关产品推荐
相关产品推荐

