场景一:

  对象转换成数组

<script>

    var people = {
        
        'susan': { 
            'age': '28',
            'sex': ''
        }
    }

    function getUsers() {
        var ret = []
        for (let [key, value] of Object.entries(people)) {
            ret.push({
                id: key,
                ...value
            })
        }
        return ret
    }

    console.log(getUsers())
</script>

 

场景二

  合并数组

<script>

    var arr1 = [1]
    var arr2 = [2, 3]
    var arr3 = [4, 5, 6]

    console.log([0, ...arr1])
    console.log([...arr1, ...arr2, ...arr3])
</script>

 

场景三

  将字符串转换成数组

<script>

    var str = 'Susan'
    console.log([...str])
</script>

 

posted on 2020-09-23 17:32  苏荷酒吧  阅读(111)  评论(0编辑  收藏  举报