当前位置:网站首页>JS to assign values to two objects with the same attributes
JS to assign values to two objects with the same attributes
2022-06-22 07:40:00 【A Huang Junhui a】
In our development process, it is possible to use two objects with the same attributes , Assign all the attribute values of this object to another object , What should be done to make it easier ?
as follows
let A = {
name:"",
age:"",
sex:"",
address:"",
grade:"",
like:" having dinner , sleep , Doudou "
};
let B = {
name:"huangjunhui",
age:40,
sex:" male ",
address:" The earth is Hubei, China ",
grade:"",
like:" Look at the beauty and smile OR Smiling at beautiful women ", // This attribute will put A In the
company:" This attribute is not public , Don't put in A in ",
}
Here is the code
Object.keys(A).forEach(i=>{
A[i] = B[i] || A[i]});
// explain obtain A Array of all keys in , Use forEach If B There is this attribute in and the value of the attribute is not empty , Just put B Attribute to A, If B There is no such attribute in the , Just use A Self
边栏推荐
- Simplicity is the best method of network promotion
- 8、 Slider assembly
- Shutter margin negative margin
- Impact of dead chain on websites
- Ffmpeg pit
- Wechat applet camouflage page (change the page content regularly)
- Flutter gets the context, and flutter gets the DOM element location
- 【图论常见模板题】4种最短路解法和2种最小生成树解法
- 微信小游戏(二)
- Use multithreading to speed up your crawler
猜你喜欢

An example shows the difference between let and VaR

Reasons and solutions for Taobao's baby's prompt "sales attribute is required and parameter format is wrong"

What are the ways for Taobao merchants to put their babies on the shelves in batches

Speed planning generation of coursera self driving car Part4 motion planning

How to upload Taobao tmall products with one click

RFID warehouse management system solution implementation visualization process

Crmeb open version 4.3

Detr3d model source code Guide & mmdetection3d construction process

Greek alphabet - system / service name commonly used in development - Collection

DETR3D模型源码导读 & MMDetection3D构建流程
随机推荐
Open source get through version - integral function
[common template problems in graph theory] four shortest path solutions and two minimum spanning tree solutions
JS native implementation for loop rendering array
4 solutions de court - circuit et 2 solutions d'arbre de génération minimum
Crmeb mall order shipping function
Wechat applet service provider sub merchant payment order interface
Xlua environment configuration
微信小游戏(二)
Open source open source version - release products
Find and replace the spaces, Nan and special symbols contained in a column of data in the dataframe
Target detection series -- detailed explanation of RCNN principle
Scrollrect for tableview
Speed planning generation of coursera self driving car Part4 motion planning
Win openfeign from simple to deep
How to import and upload a CSV generated by a third-party platform to a Taobao store
飞桨框架v2.3发布高可复用算子库PHI:重构开发范式,降本增效
EditText and Scrollview focus grabbing
报错 E: Unable to locate package sudo
Taobao assistant can not be used. How to export the baby in the warehouse to backup the data package
Applet vant UI implementation calls interface data and displays it