当前位置:网站首页>学习使用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 }
边栏推荐
- ubuntu20安裝redisjson記錄
- Function reentry, function overloading and function rewriting are understood by yourself
- Graphical tools package yolov5 and generate executable files exe
- Allow public connections to local Ruby on Rails Development Server
- About Tolerance Intervals
- Kbone与小程序跨端开发的一些思考
- 1200.Minimum Absolute Difference
- 一些常用软件相关
- [leetcode] 450 and 98 (deletion and verification of binary search tree)
- Adaptive non European advertising retrieval system amcad
猜你喜欢

哈夫曼树基本概念

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

API data interface of A-share index component data

Set static IP for raspberry pie

QT thread and other 01 concepts

Gpt-3 is a peer review online when it has been submitted for its own research

Principle of attention mechanism

浅谈网络安全之文件上传

你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?

Open3D 网格滤波
随机推荐
Termux set up the computer to connect to the mobile phone. (knock the command quickly), mobile phone termux port 8022
ubuntu20安装redisjson记录
大白话高并发(二)
Ggplot facet detail adjustment summary
Kotlin Android 环境搭建
19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
Lab1 configuration script
Hisilicon 3559 universal platform construction: RTSP real-time playback support
海思3559万能平台搭建:RTSP实时播放的支持
Vernacular high concurrency (2)
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
VHDL implementation of arbitrary size matrix multiplication
tflite模型转换和量化
.net中 接口可以有默认实现了
web服务性能监控方案
SSL证书部署
Codeworks 5 questions per day (1700 average) - day 7
It's too convenient. You can complete the code release and approval by nailing it!