array.keys in javascript code example
Example 1: js get object keys
myObject = {
"key": "value"
}
Object.keys(myObject); // get array of keys
Example 2: get all keys of object in javascript
myObject = {
"key": "value",
"key2":"value2"
}
Object.keys(myObject);
//console.log(Object.keys(myObject)) = ["key", "key2"]
Example 3: .keys() array
var arr = ['a', , 'c'];
var sparseKeys = Object.keys(arr);
var denseKeys = [...arr.keys()];
console.log(sparseKeys); // ['0', '2']
console.log(denseKeys); // [0, 1, 2]