[Javascript] Different ways to create an new array/object based on existing array/object
2017-05-17 01:56
477 查看
Array:
1. slice()
2. concat
3. spread opreator:
4. Array.from:
Object:
Shadow copy:
1. object.assign:
2. spread opreator:
Deep copy:
From lodash:
From Ramda:
JS:
1. slice()
const newAry = ary.slice()
2. concat
const newAry = [].concat(ary)
3. spread opreator:
const newAry = [...ary]
4. Array.from:
const newAry = Array.from(ary)
Object:
Shadow copy:
1. object.assign:
const newObj = Object.assign({}, obj, {prop: 'newProp'})
2. spread opreator:
const newObj = { ...obj }
Deep copy:
From lodash:
const newObj = _.cloneDeep(obj)
From Ramda:
const newObj = R.clone(obj);
JS:
const newObj = JSON.parse(JSON.stringify(obj))
相关文章推荐
- Different ways to create an object in Java
- windows 8安装,选择盘符时“Setup was unable to create a new system partition or locate an existing system partition.”
- Create a New SharePoint Permission Level and Bind it to an Existing SharePoint Group
- XPathFactory#newInstance() failed to create an XPathFactory for the default object 报错解决办法整理
- Three ways to create an HTTP Server on IBM i
- Create a New SharePoint Permission Level and Bind it to an Existing SharePoint Group
- ways to creat an object in javascript
- How To Add a New Disk(s) to An Existing Diskgroup on RAC (Best Practices).
- 安装Windows Server 2012 R2提示"unable to create a new system partition or locate an existing system partition"解决方法
- An errpr has occurred - no valid devices were found on which to create new file systems.
- [已解决]在VMware-server for linux 下装centos错误:an error has occurred. - no valid devices were found on which to create new file system
- setup was unable to create a new system partition or locate an existing system
- Object.create(): the New Way to Create Objects in JavaScript
- Create a new repository on the command line/Push an existing repository from the command line
- Divide and Conquer (1) -- Kth Largest Element in an Array,Different Ways to Add Parentheses
- Different ways to install kernel hooks under Windows NT based systems
- The ways to create object instance
- 解决此类问题:warning: unable to bind to property '' on class 'Object' (class is not an IEventDispatcher) .
- To get the tree list of the objects on which an object depends
- PDF Writer ->an article on using virtual priter method to create pdf files