当前位置:网站首页>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;
});
}
}
边栏推荐
- 话里话外:流程图绘制初级:六大常见错误
- 基于check-point实现图数据构建任务
- Application of clock wheel in RPC
- Move, say goodbye to the past again
- . Net delay queue
- PR FAQ: how to set PR vertical screen sequence?
- Accounting regulations and professional ethics [11]
- How to save the contents of div as an image- How to save the contents of a div as a image?
- The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
- Accounting regulations and professional ethics [7]
猜你喜欢

Preliminary practice of niuke.com (10)

科普达人丨一文看懂阿里云的秘密武器“神龙架构”

Function test - knowledge points and common interview questions

Big God explains open source buff gain strategy live broadcast

Web components series - detailed slides

Intranet penetrating FRP: hidden communication tunnel technology

Communication mode based on stm32f1 single chip microcomputer

Hidden communication tunnel technology: intranet penetration tool NPS

一图看懂ThreadLocal

AutoCAD - set color
随机推荐
Daily notes~
AI system content recommendation issue 24
Four point probe Industry Research Report - market status analysis and development prospect prediction
PR FAQ: how to set PR vertical screen sequence?
Principle and general steps of SQL injection
Principle and general steps of SQL injection
线程池的使用和原理
[hcie TAC] question 5 - 1
How to decrypt worksheet protection password in Excel file
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
Can I "reverse" a Boolean value- Can I 'invert' a bool?
Practice: fabric user certificate revocation operation process
Scientific research cartoon | what else to do after connecting with the subjects?
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Market trend report, technical innovation and market forecast of electrochromic glass and devices in China and Indonesia
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
[flask] ORM one to many relationship
Big God explains open source buff gain strategy live broadcast
基于check-point实现图数据构建任务
FIREBIRD使用经验总结