ES6小练习(去掉数组的某个属性、重复元素以及对象最大值)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <script type="text/javascript">
        // 作业1:实现一个函数,将现有数组内每个对象的checked属性去掉,
        let arr = [
                {featureId: 1, featureContent: '全新未用', checked: '0'},
                {featureId: 2, featureContent: '验货面付', checked: '0'},
                {featureId: 3, featureContent: '快递包邮', checked: '0'},
                {featureId: 4, featureContent: '保修期内', checked: '0'},
                {featureId: 5, featureContent: '专柜正品', checked: '0'},
                {featureId: 6, featureContent: '有发票', checked: '0'}
            ];
            for(let i of arr){
            let newVar =(({featureId,featureContent})=>({featureId,featureContent}))(i)
            console.log(newVar)
            }
            
        // 作业2:实现一个函数,传入一个array,返回去除了重复元素的新array。例如:[1,1,2,2,3,4,5,6,1,3,6,7]
        var mySet = new Set([1,1,2,2,3,4,5,6,1,3,6,7]);
        // console.log([...mySet]);
        function distinctarr(mySet){
            var arr=new Set(mySet)
            return [...arr];
        }
        console.log(distinctarr(mySet));        
        //作业3:实现一个函数,传入下列设对象,要求输出工资最高的人的姓名。
        let emp = {
            "John": 100,
            "Pete": 300,
            "Mary": 250,
            "fuck": 400,
            "Jame": 450,
            "kobe": 550
        }
        function maxEmp(emp) {
           let max = 0
           let name
           for (let [key, val] of Object.entries(emp)) {
            if (val > max) {
             max = val
             name = key
            }
           }
           return name
          }
          console.log(maxEmp(emp));
    </script>
    <body>
    </body>
</html>

 运行效果:

 

posted @ 2021-09-28 22:18  活在记忆里的人  阅读(672)  评论(3编辑  收藏  举报