最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript遍歷json對象的key和任意js對象屬性實例

 更新時間:2017年03月09日 10:14:46   投稿:jingxian  
下面小編就為大家?guī)硪黄猨avascript遍歷json對象的key和任意js對象屬性實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

使用 keys 方法獲取該對象的屬性和方法:

 function Pasta(grain, width, shape) {
        this.grain = grain;
        this.width = width;
        this.shape = shape;
        this.toString = function () {
          return (this.grain + ", " + this.width + ", " + this.shape);
        }
      }
      
      var spaghetti = new Pasta("wheat", 0.2, "circle");
      var arr = Object.keys(spaghetti);
      document.write(arr);

結(jié)果圖:

顯示 Pasta 對象中以字母“g”開頭的所有可枚舉屬性的名稱:

function Pasta(grain, width, shape) {
        this.grain = grain;
        this.width = width;
        this.shape = shape;
      }

      function CheckKey(value) {
        var firstChar = value.substr(0, 1);
        if (firstChar.toLowerCase() == "g") {
          return true;
        } else {
          return false;
        }
      }

      var polenta = new Pasta("corn", 1, "mush");
      var keys = Object.keys(polenta).filter(CheckKey);
      document.write(keys);

結(jié)果如圖:

遍歷json對象的鍵:

var an_obj = { 100: 'a', 2: 'b', 7: 'c', "name": "wu", "interesting": "Game" };
 document.write(Object.keys(an_obj));

結(jié)果如圖:


以上這篇javascript遍歷json對象的key和任意js對象屬性實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

汉寿县| 渭南市| 左权县| 禹州市| 资阳市| 周至县| 玉屏| 通许县| 辰溪县| 丹棱县| 沾益县| 石嘴山市| 济南市| 宁远县| 七台河市| 梅河口市| 义乌市| 普兰店市| 永济市| 昂仁县| 钦州市| 平邑县| 上高县| 平顶山市| 宜丰县| 丁青县| 蕉岭县| 南召县| 贡嘎县| 丰镇市| 望城县| 高雄县| 永安市| 和林格尔县| 微山县| 松桃| 建宁县| 丹寨县| 逊克县| 比如县| 古交市|