Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

javascript - 检查jquery映射对象是否为null? 适用于IE和Chrome浏览器(Check jquery map object null or not ? for both IE and Chrome browser)

如何在chrome和IE浏览器中检查javascript映射对象是否为null或为空?

  ask by Vicky Singh Gill translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add this to code for IE browser support in your javascript :

(将此添加到您的javascript中的IE浏览器支持代码中:)

if (!Object.entries)
  Object.entries = function( obj ){
    var ownProps = Object.keys( obj ),
        i = ownProps.length,
        resArray = new Array(i); // preallocate the Array
    while (i--)
      resArray[i] = [ownProps[i], obj[ownProps[i]]];

    return resArray;
  };

For Chrome not required due to polyfill default avaialble.

(对于Chrome,由于polyfill默认可用,因此不需要。)

To check the map is null or not :

(要检查地图是否为空:)

if(Object.entries(mapObj).length > 0){}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...