zoukankan      html  css  js  c++  java
  • JS === 类数组(伪数组)

    // 今天跟成哥学习了类数组的相关用法,涨见识了,记录一下~

    类数组:

    //属性要为索引(数字)属性,必须要有length属性,最好要加上push

    Array.prototype.push = function(target){
      
       obj[obj.length] = target;
       obj.length++;          
    }
    var obj = {
       
    "2" : " a",
    "3" :  "b",
    "length" : 2,
    "push" : Array.prototype.push
    //
    "splice":Array.prototype.splice

    //当加上这个splice属性后,此对象会以数组的形式显现,但仍然是对象。
    } 

    obj.push(
    'c'); ====> obj[obj.length] = target; 所以 obj[2] = "c" obj.length = 3
    obj.push(
    'd');  ====> obj[obj.length] = target; 所以 obj[3] = "d" obj.length = 4




    ======> 最后的
    obj {
    "2" : "c",
    "3" : "d",
    "length" : 4,

    }
  • 相关阅读:
    database join
    图像超分辨率重建
    信号处理
    将博客搬至CSDN
    Openstack
    nginx的优化
    CentOS系统的优化
    zabbix服务端客户端部署
    MySQL优化必须调整的10项配置
    TCP三次握手
  • 原文地址:https://www.cnblogs.com/rabbit-lin0903/p/11318553.html
Copyright © 2011-2022 走看看