js中的对象获取索引

Object.keys( object)

Object.keys返回js对象或者数组的索引

var obj = {'a': 'Beijing', 'b': 'Haidian'};

console.log(Object.keys(obj)); //['a', 'b']

var arr = ["a", "b", "c"];

console.log(Object.keys(arr));//["0", "1", "2"]

 

 

你可能感兴趣的:(js)