当前位置:网站首页>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;
});
}
}
边栏推荐
- Summary of database 2
- [flask] ORM one to many relationship
- Understand asp Net core - Authentication Based on jwtbearer
- Working group and domain analysis of Intranet
- Market trend report, technical innovation and market forecast of taillight components in China
- 线程池的使用和原理
- Market trend report, technical innovation and market forecast of electrochromic glass and devices in China and Indonesia
- Research Report of exoskeleton robot industry - market status analysis and development prospect prediction
- Will the memory of ParticleSystem be affected by maxparticles
- [Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
猜你喜欢
Vscode setting outline shortcut keys to improve efficiency
Actual combat | use composite material 3 in application
Web components series - detailed slides
Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
How was MP3 born?
Understand asp Net core - Authentication Based on jwtbearer
QT graphical view frame: element movement
@EnableAspectAutoJAutoProxy_ Exposeproxy property
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Function test - knowledge points and common interview questions
随机推荐
Hair and fuzz interceptor Industry Research Report - market status analysis and development prospect forecast
What encryption algorithm is used for the master password of odoo database?
Recommend 10 excellent mongodb GUI tools
error: ‘connect‘ was not declared in this scope connect(timer, SIGNAL(timeout()), this, SLOT(up
AutoCAD - set color
Accounting regulations and professional ethics [8]
Principle and general steps of SQL injection
线程池的使用和原理
Practice: fabric user certificate revocation operation process
How to decrypt worksheet protection password in Excel file
How to save the contents of div as an image- How to save the contents of a div as a image?
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
@EnableAspectAutoJAutoProxy_ Exposeproxy property
Model fusion -- stacking principle and Implementation
A trap used by combinelatest and a debouncetime based solution
多年锤炼,迈向Kata 3.0 !走进开箱即用的安全容器体验之旅| 龙蜥技术
Actual combat | use composite material 3 in application
The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
Audio and video technology development weekly | 252
Review of Weibo hot search in 2021 and analysis of hot search in the beginning of the year