当前位置:网站首页>学习使用js把两个对象合并成一个对象的方法Object.assign()
学习使用js把两个对象合并成一个对象的方法Object.assign()
2022-07-06 21:09:00 【徊忆羽菲】
学习使用js把两个对象合并成一个对象的方法Object.assign
Object.assign() 方法
Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象。它将返回目标对象
合并对象
var o1 = {
a: 1 };
var o2 = {
b: 2 };
var o3 = {
c: 3 };
var obj = Object.assign(o1, o2, o3);
console.log(obj); // { a: 1, b: 2, c: 3 }
console.log(o1); // { a: 1, b: 2, c: 3 }, 注意目标对象自身也会改变
合并具有相同属性的对象
var o1 = {
a: 1, b: 1, c: 1 };
var o2 = {
b: 2, c: 2 };
var o3 = {
c: 3 };
var obj = Object.assign({
}, o1, o2, o3);
console.log(obj); // { a: 1, b: 2, c: 3 }
边栏推荐
- Class常量池与运行时常量池
- QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)
- Free PHP online decryption tool source code v1.2
- Implementation steps of docker deploying mysql8
- On file uploading of network security
- Termux set up the computer to connect to the mobile phone. (knock the command quickly), mobile phone termux port 8022
- Restcloud ETL Community Edition June featured Q & A
- HW notes (II)
- Kbone与小程序跨端开发的一些思考
- MySQL的索引
猜你喜欢

Construction of Hisilicon universal platform: color space conversion YUV2RGB

Introduction to opensea platform developed by NFT trading platform (I)

QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)

ubuntu20安装redisjson记录

About Confidence Intervals

Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND

机器学习笔记 - 使用机器学习进行鸟类物种分类

QT 打开文件 使用 QFileDialog 获取文件名称、内容等

My brave way to line -- elaborate on what happens when the browser enters the URL

Restcloud ETL Community Edition June featured Q & A
随机推荐
【mysql】mysql中行排序
如何自定义Latex停止运行的快捷键
VHDL implementation of single cycle CPU design
How to detect whether the MySQL code runs deadlock +binlog view
Docker部署Mysql8的实现步骤
一些常用软件相关
CMB's written test - quantitative relationship
Lab1 configuration script
C task expansion method
Allow public connections to local Ruby on Rails Development Server
SSL certificate deployment
Create commonly used shortcut icons at the top of the ad interface (menu bar)
机器学习笔记 - 使用机器学习进行鸟类物种分类
codeforces每日5题(均1700)-第七天
web服务性能监控方案
My brave way to line -- elaborate on what happens when the browser enters the URL
卡尔曼滤波-1
Introduction to opensea platform developed by NFT trading platform (I)
ubuntu20安装redisjson记录
Native MySQL