08 笔记

 数组

<body>
    <script>
        let array = [1,2,3,4,5]
        console.log(array);//12345
        console.log(array[1]);//2

        // 数组的长度
      console.log(array.length);//5

    //   遍历数组
    for (let i = 0; i < array.length; i++) {
        console.log(array[i]);
        // console.log(array[2]);
        // console.log(array[5]);
        // console.log(array[1]);
        // console.log(array[2]);
        // console.log(array[3]);
        // console.log(array[4]);
        // console.log(array[5]);
        
    }
    
    </script>

</body>

 

 数组增删改查

 

<body>
    <script>
        let array = [1,2,3,4,5]
        // 数组新增,push添加到末尾
        array.push(6)
        console.log(array);//[1,2,3,4,5,6]

        // 数组的新增,unshift添加到开头
        array.unshift(0)
        console.log(array);//[0,1,2,3,4,5,6]

        // 数组删除pop
        array.pop(6)
        console.log(array);
        //删除第一个数组shift
        array.shift(array);

    //    数组的删除指定元素
    // 数组名字.sploce(start,deletCount)
    // 从0开始咯
    // 如果删除数组量
    array.splice(1,3)
    console.log(array);//1,5
    
    // 数组赋值
    array[0] = '6'
     console.log(array);
     array[3] = '48'
     console.log(array);
   

    </script>
    
</body>

 

 

 map数组遍历器

filter用给定条件过滤

forEach数组遍历器

<body>
    <script>
            let arr = [11,22,33,44,55,66]; 
         //数组中每一个元素+2
         let arr1 = arr.map((value, index) => { 
            return value +2;
         })
        //让每一个元素的值+
        console. log(arr1); //[13, 24, 35, 46, 57, 68]
        //数组中的每一个元素*2 
        let arr2=arr.map((value,index)=> {
            return value *2;
         })  
        console.log(arr2); // [22, 44, 66, 88, 110, 132]

        // forEach
           arr. forEach((item, index) => { 
            console.log(`下标为${index}的元素是${item}`); 
           })

            // 03-forEach数组遍历器.html:20下标为0的元素是11
            // 03-forEach数组遍历器.html:20下标为1的元素是22
            // 03-forEach数组遍历器.html:20下标为2的元素是33
            // 03-forEach数组遍历器.html:20下标为3的元素是44
            // 03-forEach数组遍历器.html:20下标为4的元素是55
            // 03-forEach数组遍历器.html:20下标为5的元素是66
         
         //(1)需求:找出数组中的偶数 
         let arr7 = arr.filter((item) => {
            return item % 2 == 0;
            
         })
         console.log(arr7);
         //(5)[60,88,90,108,260] 0;
    </script>
  
    
</body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值