<bdo id='abHXn'></bdo><ul id='abHXn'></ul>

    1. <i id='abHXn'><tr id='abHXn'><dt id='abHXn'><q id='abHXn'><span id='abHXn'><b id='abHXn'><form id='abHXn'><ins id='abHXn'></ins><ul id='abHXn'></ul><sub id='abHXn'></sub></form><legend id='abHXn'></legend><bdo id='abHXn'><pre id='abHXn'><center id='abHXn'></center></pre></bdo></b><th id='abHXn'></th></span></q></dt></tr></i><div id='abHXn'><tfoot id='abHXn'></tfoot><dl id='abHXn'><fieldset id='abHXn'></fieldset></dl></div>

    2. <legend id='abHXn'><style id='abHXn'><dir id='abHXn'><q id='abHXn'></q></dir></style></legend>
    3. <tfoot id='abHXn'></tfoot>

      <small id='abHXn'></small><noframes id='abHXn'>

        javascript .filter() 真正的布尔值

        javascript .filter() true booleans(javascript .filter() 真正的布尔值)

      1. <legend id='uxSoy'><style id='uxSoy'><dir id='uxSoy'><q id='uxSoy'></q></dir></style></legend>

        <small id='uxSoy'></small><noframes id='uxSoy'>

      2. <i id='uxSoy'><tr id='uxSoy'><dt id='uxSoy'><q id='uxSoy'><span id='uxSoy'><b id='uxSoy'><form id='uxSoy'><ins id='uxSoy'></ins><ul id='uxSoy'></ul><sub id='uxSoy'></sub></form><legend id='uxSoy'></legend><bdo id='uxSoy'><pre id='uxSoy'><center id='uxSoy'></center></pre></bdo></b><th id='uxSoy'></th></span></q></dt></tr></i><div id='uxSoy'><tfoot id='uxSoy'></tfoot><dl id='uxSoy'><fieldset id='uxSoy'></fieldset></dl></div>

                <tfoot id='uxSoy'></tfoot>
                  <tbody id='uxSoy'></tbody>
                  <bdo id='uxSoy'></bdo><ul id='uxSoy'></ul>
                • 本文介绍了javascript .filter() 真正的布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  function bouncer(arr) {
                    // Don't show a false ID to this bouncer.
                      function a(b) {
                        if(b !== false) {
                          return b;
                        }
                      }
                  
                      arr = arr.filter(a);
                      return arr;
                  }
                  
                  bouncer([7, 'ate', '', false, 9]);
                  

                  我只需要返回真正的布尔语句,当我运行这段代码时,它就可以工作了.但是,我很困惑,因为我的if 语句"无论是 b !== true 还是 b !== false 都会起作用.有人可以解释一下为什么这两种方式都有效吗?

                  I have to return true boolean statements only, and when I run this code, it works. However, I am quite confused because my "if statement" will work whether it's b !== true or b !== false. Could someone please explain the reason why this works both ways?

                  推荐答案

                  显然 .filter() 是在 ES5 中引入的.

                  Apparently .filter() was introduced in ES5.

                  这无疑帮助我了解了这里发生的事情.希望对您有所帮助!

                  This definitely helped me wrap my mind around what's going on here. Hope it helps!

                  基本上,写作:

                  arr.filter(Boolean)
                  

                  同写:

                  arr.filter( function(x) { return Boolean(x); }); 
                  

                  因为 Boolean() 也是一个函数,当为真时返回真,当为假时返回假!

                  since Boolean() is also a function that returns truthy when true and falsy when false!

                  例子:

                  var a = [1, 2, "b", 0, {}, "", NaN, 3, undefined, null, 5];
                  
                  var b = a.filter(Boolean);  // [1, 2, "b", {}, 3, 5]; 
                  

                  来源:这里.

                  这篇关于javascript .filter() 真正的布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                  <legend id='2zXzy'><style id='2zXzy'><dir id='2zXzy'><q id='2zXzy'></q></dir></style></legend>
                  1. <i id='2zXzy'><tr id='2zXzy'><dt id='2zXzy'><q id='2zXzy'><span id='2zXzy'><b id='2zXzy'><form id='2zXzy'><ins id='2zXzy'></ins><ul id='2zXzy'></ul><sub id='2zXzy'></sub></form><legend id='2zXzy'></legend><bdo id='2zXzy'><pre id='2zXzy'><center id='2zXzy'></center></pre></bdo></b><th id='2zXzy'></th></span></q></dt></tr></i><div id='2zXzy'><tfoot id='2zXzy'></tfoot><dl id='2zXzy'><fieldset id='2zXzy'></fieldset></dl></div>
                      <bdo id='2zXzy'></bdo><ul id='2zXzy'></ul>

                          <tbody id='2zXzy'></tbody>

                          <tfoot id='2zXzy'></tfoot>
                          • <small id='2zXzy'></small><noframes id='2zXzy'>