当前位置:网站首页>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'}
边栏推荐
- STM32状态机编程实例——全自动洗衣机(下)
- WAF details
- [programmers must] Tanabata confession strategy: "the moon meets the cloud, the flowers meet the wind, and the night sky is beautiful at night". (with source code Collection)
- [cloud native] talk about the understanding of the old message middleware ActiveMQ
- booking.com缤客上海面经
- General test case writing specification
- Educational Codeforces Round 132 (Rated for Div. 2) E. XOR Tree
- Find My技术|物联网资产跟踪市场规模达66亿美元,Find My助力市场发展
- 测试用例设计方法之:入门试招,等价边界初探
- Operator new, operator delete supplementary handouts
猜你喜欢

Booking.com binke Shanghai noodles

Wechat applet to realize music player (4) (use pubsubjs to realize inter page communication)

Sentinel fusing and current limiting

第十八章:2位a~b进制中均位奇观探索,指定整数的 3x+1 转化过程,指定区间验证角谷猜想,探求4份黑洞数,验证3位黑洞数

Luoda development - audio stream processing - AAC / loopbacktest as an example

触觉智能分享-RK3568在景区导览机器人中的应用

day03_ 1_ Idea tutorial

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

深度学习之DAT

Luoda Development -- the context of sidetone configuration
随机推荐
PHP 对象转换数组
zkEVM:MINA的CEO对zkEVM和L1相关内容的总结
What are the differences between vite and wenpack?
加班一周开发了报表系统,这个低代码免费IT报表神器太好用了
booking.com缤客上海面经
UFS Clk Gate介绍
Acwing game 61 [End]
operator new、operator delete补充讲义
E-commerce operator Xiaobai, how to get started quickly and learn data analysis?
中国数据库 OceanBase 入选 Forrester Translytical 数据平台报告
Leetcode: 102. Sequence traversal of binary tree
【Unity3d Shader】角色投影与倒影
php 查找 session 存储文件位置的方法
在 Istio 服务网格内连接外部 MySQL 数据库
PHP <=> 太空船运算符(组合比较符)
Can't the container run? The Internet doesn't have to carry the blame
Go Plus Security:一款Build Web3不可或缺的安全生态基础设施
ASEMI整流桥GBU1510参数,GBU1510规格,GBU1510封装
Realization of online shopping mall system based on JSP
[MCU simulation project] external interrupt 0 controls 8 LED flashes