场景一:
对象转换成数组
<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>