当前位置:网站首页>JS get some attributes of the object
JS get some attributes of the object
2022-07-26 04:03:00 【Is it Luoluo】
obj Data objects
let obj = {
name:'fasf',
age:18,
sef:'gsadf',
fj:'goiop',
fupo:'hoipgeu'
}
1. Ordinary function
// Returns the object obj Some key value pairs in , keys Is a key value sequence
function partObject(obj,keys){
if(!keys instanceof Array || keys.length === 0)
return
let returnObj = {
}
keys.forEach(item => {
if(obj.hasOwnProperty(item))
returnObj[item] = obj[item]
})
return returnObj
}
console.log(obj.add(2,3))
let props = ['age','sef','fupo']
let result = partObject(obj,props)
console.log(result)
//{age: 18, sef: 'gsadf', fupo: 'hoipgeu'}
2. prototype Prototype
Object.prototype.partObject = function(keys){
if(!keys instanceof Array || keys.length === 0)
return
let returnObj = {
}
keys.forEach(item => {
if(this.hasOwnProperty(item))
returnObj[item] = this[item]
})
return returnObj
}
let props = ['age','sef','fupo']
let result = obj.partObject(props)
console.log(result)
// {age: 18, sef: 'gsadf', fupo: 'hoipgeu'}
边栏推荐
- Leetcode: 102. Sequence traversal of binary tree
- KBPC1510-ASEMI大芯片15A整流桥KBPC1510
- 容器跑不动?网络可不背锅
- Booking.com binke Shanghai noodles
- Kbpc1510-asemi large chip 15A rectifier bridge kbpc1510
- Go Plus Security:一款Build Web3不可或缺的安全生态基础设施
- Opencv learning notes -- Hough transform
- php eval() 函数可以将一个字符串当做 php 代码来运行
- How to use graffiti magic color product development kit
- Luoda Development -- the context of sidetone configuration
猜你喜欢

Introduction to UFS CLK gate

Supervit for deep learning

CPU and GPU are out of date, and the era of NPU and APU begins

开源许可证的传染性问题浅析

【云原生】谈谈老牌消息中间件ActiveMQ的理解

How to build an enterprise level OLAP data engine for massive data and high real-time requirements?

Acwing第 61 场周赛【完结】

redux

2021 CIKM |GF-VAE: A Flow-based Variational Autoencoder for Molecule Generation

Redis如何实现持久化?详细讲解AOF触发机制及其优缺点,带你快速掌握AOF
随机推荐
STM32状态机编程实例——全自动洗衣机(下)
If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
【Unity3d Shader】角色投影与倒影
Testing is not valued? Senior: you should think in another position
How to build an enterprise level OLAP data engine for massive data and high real-time requirements?
Wechat applet realizes music player (5)
Zkevm: summary of zkevm and L1 by Mina's CEO
The PHP Eval () function can run a string as PHP code
KBPC1510-ASEMI大芯片15A整流桥KBPC1510
Implementation of distributed lock
PHP 对象转换数组
booking.com缤客上海面经
PHP < => spacecraft operator (combined comparator)
微信小程序实现音乐播放器(5)
Failed to install the hcmon driver
Inventory the concept, classification and characteristics of cloud computing
php中可以使用取绝对值函数 abs() 将负数转成正数
测试用例设计方法之:入门试招,等价边界初探
[in depth study of 4g/5g/6g topic-42]: urllc-13 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -7-low delay technology-1-subcarrier spacing expansio
[question 019: what is the understanding of spherecastcommand in unity?]