我有一个JavaScript对象,例如
var obj = { key1: 'value1', key2: 'value2', key3: 'value3', key4: 'value4' }
如何获取此对象中键的长度和列表?
var obj = {
key1: 'value1', key2: 'value2', key3: 'value3', key4: 'value4' }; var keys = []; for (var k in obj) keys.push(k); alert("total " + keys.length + " keys: " + keys);