Java Script学习之旅——第八天

学习主体:

Java Script学习视频15集

学习内容:

  1. 构造函数、实例化执行过程
  2. 基本包装类型
  3. Object静态方法
  4. 数组reduce累计方法
  5. 数组find

学习代码:

                                                   forEach遍历数组、构造函数:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*const arr = ['pink', 'white', 'skyblue']
    arr.forEach(function (items, index) {
      console.log(items)//数组元素,一定要写
      console.log(index)//索引号,可不写
    })//forEach不需要返回值*/
    function Goods(uname, price, count) {
      this.uname = uname
      this.price = price
      this.count = count
    }
    const mi = new Goods('小米', 1999, 3)
    console.log(mi)
    const huawei = new Goods('华为', 3999, 5)
    console.log(huawei)
    const vivo = new Goods('vivo', 2899, 3)
    console.log(vivo)
  </script>
</body>

</html>

                                                        数组reduce累计方法: 

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const arr = [{
      uname: '小王',
      salary: 10000
    }, {
      uname: '小李',
      salary: 10000
    }, {
      uname: '小张',
      salary: 10000
    }
    ]
    //const total = arr.reduce((prev, current) => {
    //  return prev + current.salary
    //}, 0)
    //console.log(total)
    //涨薪后
    const total = arr.reduce((prev, current) => {
      return prev + current.salary * 1.3
    }, 0)
    console.log(total)
  </script>
</body>

</html>

                                                                 数组find:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const arr = [
      {
        uname: '小米',
        price: '1999'
      },
      {
        uname: '华为',
        price: '3999'
      },
    ]
    //const mi = arr.find(function (item) {
    // console.log(111)
    //return item.uname === '小米'
    //})
    //console.log(mi)
    const mi = arr.find(item => item.uname === '小米')
    console.log(mi)
  </script>
</body>

</html>

 

 

  • 2023.8.2

学习计划:

  • JS视频快速学习;
  • 算法还未开始,有空时间要开始了解
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值