赞
踩
作用在对象上,返回一个对象。取出对象所有可遍历属性,返回一个新的对象可以进行拷贝
- let person = { name:'张三',age:18}
-
- let someone = {...person}
-
- console.log(someone) //返回 { name:'张三',age:18}
- let array = ['a','b','c']
-
- let obj = {...array}
-
- console.log(obj) // {0:'a',1:'b',2:'c'}
-
说明:给数组的每个元素生成key,从0开始返回一个新的对象
- let name = { name:'张三'}
-
- let age = { age:18}
-
- let person ={...name,...age}
-
- console.log(person) //{name:'张三',age:18}
- let person = {name: "Amy", age: 15};
-
- let someone = { ...person, name: "Mike", age: 17};
-
- console.log(someone); //{name: "Mike", age: 17}
说明:自定义属性和扩展属性相同的时候,将会被覆盖。自定义属性在前,扩展属性覆盖自定义属性。反之则是自定义属性覆盖拓展属性。
- let person = {name: "Amy", age: 15};
-
- let someone = {name: "Mike", age: 17, ...person};
-
- console.log(someone); //{name: "Amy", age: 15}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。