当前位置:网站首页>Object.keys
Object.keys
2022-08-11 05:17:00 【-加油】
1、对象
let data = {
a:'aaa',
b:'bbb',
c:'ccc',
d:'ddd'
}
console.log(data);//{ a: 'aaa', b: 'bbb', c: 'ccc', d: 'ddd' }
//以数组的方式 获取对象的key
console.log(Object.keys(data));//[ 'a', 'b', 'c', 'd' ]
//数组可用 数组方法进行遍历
Object.keys(data).forEach(key=>{
console.log(data[key]);
//aaa
//bbb
//ccc
//ddd
})
2、数组
let arr = ['a','b','c','d','e']
//以数组方式 获取索引:下标位置
console.log(Object.keys(arr));//[ '0', '1', '2', '3', '4' ]
3、字符串
let str = 'abcde'
//以数组方式 获取索引:下标位置
console.log(Object.keys(str));//[ '0', '1', '2', '3', '4' ]
4、构造函数与实例
function Fn(name,age,sex){
this.name = name
this.age = age
this.sex = sex
this.say = function(){
console.log('hello');
}
}
let s = new Fn('zs','18','男')
console.log(Object.keys(Fn));//[]
console.log(Object.keys(s));//[ 'name', 'age', 'sex', 'say' ]
边栏推荐
- 【转载】如何理解数据集中【训练集】、【验证集】和【测试集】
- 【网站小白】Hibernate插入数据成功,不报错,但是数据库中没有值
- task02 fashion-mnist分类实战
- 手推卷积神经网络参数(卷积核)求导
- Chapter 13 Class Inheritance
- (一)性能实时监控平台搭建(Grafana+Influxdb+Jmeter)
- 【记录】innerHeight?clientHeight?offsetHeight?scrollTop?screenTop?.....一堆高度傻傻分不清
- 【C语言从初阶到进阶】第一篇 初始C语言(一)
- Flask framework learning: template inheritance
- 第6章 分支语句和逻辑运算符
猜你喜欢
随机推荐
04-开发自己的npm包及发布流程详细讲解
Introduction of several ways to initialize two-dimensional arrays in C language (private way to initialize large arrays)
数组的用法
Solidrun hummingboard制作SD卡
第10章 对象和类-2
吃瓜教程task01 第2章 模型评估与选择
吃瓜教程task03 第4章 决策树
开炮,开炮
LeetCode43. String multiplication (this method can be used to multiply large numbers)
【记录】ES6
(1) Docker installs Redis in practice (one master, two slaves, three sentinels)
task05 PyTorch可视化
【转载】如何理解数据集中【训练集】、【验证集】和【测试集】
The most complete installation tutorial of Pytorch (one step)
Redis - the solution to the failure of connecting to the redis server in linux using jedis
Redis - Data Types (Basic Instructions, String, List, Set, Hash, ZSet, BitMaps, HyperLogLog, GeoSpatial) / Publish and Subscribe
【win10+cuda7.5+cudnn6.0安装caffe⑥】报错及处理方式
CSDN 社区内容创作规范
[C language advanced] The first in-depth analysis of the storage of integer data in memory (1)
07-JS事件:事件类型、事件对象、事件传播、事件委托









