首页 > 代码库 > 获取对象的键值名

获取对象的键值名

var demoArr = [‘Javascript‘, ‘Gulp‘, ‘CSS3‘, ‘Grunt‘, ‘jQuery‘, ‘angular‘];
var demoObj = {
aaa: ‘Javascript‘,
bbb: ‘Gulp‘,
ccc: ‘CSS3‘,
ddd: ‘Grunt‘,
eee: ‘jQuery‘
};

1.Object.keys(demoObj) //[‘aaa‘,‘bbb‘,‘ccc‘,‘ddd‘,‘eee‘];

2.$.each(demoArr, function(e, ele) {
  console.log(e, ele);
})
//输出
0 "Javascript"
1 "Gulp"
2 "CSS3"
3 "Grunt"
4 "jQuery"

获取对象的键值名