最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ReferenceError: Set is not defined. Error utilizing Set data structure in Ionic app - Stack Overflow

programmeradmin7浏览0评论

I have an ionic app that uses the set data structure in one of it's method. When I try to run the app on my android device(Android 5.0.2,API 21), I run into this error

ReferenceError: Set is not defined
at Object.myMethod

Here is a code snippet showing the line responsible for the error

myMethod: function(userid) {


      var user = [];

      var service = this;
      var userIDs = new Set();
      var promises = [];
    ...}

I am not a javascript guru but it seems to me that it might be a problem with the android web view on my device not having a built in implementation of the Set data structure. To further confuse matters, I tested this same app on another device(HTC One M8(Android 5.0.1,API 21)) and it worked fine with no errors shown. Does anybody know how to fix this?

I have an ionic app that uses the set data structure in one of it's method. When I try to run the app on my android device(Android 5.0.2,API 21), I run into this error

ReferenceError: Set is not defined
at Object.myMethod

Here is a code snippet showing the line responsible for the error

myMethod: function(userid) {


      var user = [];

      var service = this;
      var userIDs = new Set();
      var promises = [];
    ...}

I am not a javascript guru but it seems to me that it might be a problem with the android web view on my device not having a built in implementation of the Set data structure. To further confuse matters, I tested this same app on another device(HTC One M8(Android 5.0.1,API 21)) and it worked fine with no errors shown. Does anybody know how to fix this?

Share Improve this question asked Aug 9, 2016 at 15:50 OyebisiOyebisi 7542 gold badges11 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You should try a polyfill for those devices that does not support Set:

https://github./medikoo/es6-set

It's not the most optimal option, but you could use dictionary with boolean values...

var userIDs = {};
userID["anyUserId"] = true;
发布评论

评论列表(0)

  1. 暂无评论