当前位置:网站首页>Object.keys()的用法
Object.keys()的用法
2022-07-04 14:57:00 【大象与小蚂蚁】
Object.keys(obj)
- 参数:要返回其枚举自身属性的对象
- 返回值:一个表示给定对象的所有可枚举属性的字符串数组
1.处理对象,返回可枚举的属性数组
let person = {
name:"张三",age:25,address:"深圳",getName:function(){
}};
console.log(Object.keys(person));
Object.keys(item.alarmAttribute || {
}).length)
2.处理数组,返回索引值数组
let arr = [1,2,3,4,5,6];
console.log(Object.keys(arr)); //["0", "1", "2", "3", "4", "5"]
3.处理字符串,返回索引值数组
let str = "ikun你好";
console.log(Object.keys(str)); // ["0", "1", "2", "3", "4", "5"]
4.常用技巧
let person = {
name:"张三",age:25,address:"深圳",getName:function(){
}};
Object.keys(person).map((key)=>{
console.log(person[key]); // 获取到属性对应的值,做一些处理
})
项目中使用
Object.keys(dvehicleInfo).forEach(key => {
if (key === "containervolume" && dvehicleInfo[key] === "") {
this.Volume_Static = 1;
if (dvehicleInfo.container) {
dvehicleInfo.container.split(",").map((item, index) => {
this.containerOptions[index].len = item;
});
}
}
边栏推荐
- Application and Optimization Practice of redis in vivo push platform
- Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
- Cut! 39 year old Ali P9, saved 150million
- 时钟轮在 RPC 中的应用
- Expression #1 of ORDER BY clause is not in SELECT list, references column ‘d.dept_ no‘ which is not i
- China's plastic processing machinery market trend report, technological innovation and market forecast
- . Net delay queue
- Scientific research cartoon | what else to do after connecting with the subjects?
- @EnableAspectAutoJAutoProxy_ Exposeproxy property
- Redis' optimistic lock and pessimistic lock for solving transaction conflicts
猜你喜欢
一图看懂ThreadLocal
What is torch NN?
Communication mode based on stm32f1 single chip microcomputer
Audio and video technology development weekly | 252
嵌入式软件架构设计-函数调用
How to decrypt worksheet protection password in Excel file
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
AutoCAD - set color
Qt---error: ‘QObject‘ is an ambiguous base of ‘MyView‘
Understand asp Net core - Authentication Based on jwtbearer
随机推荐
APOC自定义函数和过程
如何为ONgDB核心项目源码做贡献
Oracle监听器Server端与Client端配置实例
话里话外:流程图绘制初级:六大常见错误
Understand the rate control mode rate control mode CBR, VBR, CRF (x264, x265, VPX)
Find numbers
Daily notes~
D3D11_ Chili_ Tutorial (2): draw a triangle
Interface test - knowledge points and common interview questions
Object distance measurement of stereo vision
[North Asia data recovery] a database data recovery case where the disk on which the database is located is unrecognized due to the RAID disk failure of HP DL380 server
[Chongqing Guangdong education] National Open University spring 2019 1396 pharmaceutical administration and regulations (version) reference questions
Vscode prompt Please install clang or check configuration 'clang executable‘
Filtered off site request to
TypeError: list indices must be integers or slices, not str
The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it
Redis' optimistic lock and pessimistic lock for solving transaction conflicts
AI system content recommendation issue 24
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
Anta is actually a technology company? These operations fool netizens