我有一个 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); console.log("total " + keys.length + " keys: " + keys);