当前位置:网站首页>学习使用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 }
边栏推荐
- [safe office and productivity application] Shanghai daoning provides you with onlyoffice download, trial and tutorial
- ubuntu20安装redisjson记录
- Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND
- 接口数据安全保证的10种方式
- [development software] tilipa Developer Software
- 如何自定义Latex停止运行的快捷键
- Create commonly used shortcut icons at the top of the ad interface (menu bar)
- Open3D 网格滤波
- qt-线程等01概念
- Allow public connections to local Ruby on Rails Development Server
猜你喜欢
卡尔曼滤波-1
接口数据安全保证的10种方式
【安全攻防】序列化与反序列,你了解多少?
[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
QT thread and other 01 concepts
20.(arcgis api for js篇)arcgis api for js面采集(SketchViewModel)
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
Construction of Hisilicon universal platform: color space conversion YUV2RGB
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
24. (ArcGIS API for JS) ArcGIS API for JS point modification point editing (sketchviewmodel)
随机推荐
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
Can the applet run in its own app and realize live broadcast and connection?
The true face of function pointer in single chip microcomputer and the operation of callback function
运算放大器应用汇总1
What is Ba? How about Ba? What is the relationship between Ba and Bi?
Set static IP for raspberry pie
如何检测mysql代码运行是否出现死锁+binlog查看
Create commonly used shortcut icons at the top of the ad interface (menu bar)
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
qt-线程等01概念
[security attack and Defense] how much do you know about serialization and deserialization?
How to customize the shortcut key for latex to stop running
链表面试常见题
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
API data interface of A-share index component data
Delete data in SQL
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
pip只下载不安装
21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)