1var foo = {
2 'alpha': 'puffin',
3 'beta': 'beagle'
4};
5
6var keys = Object.keys(foo);
7console.log(keys) // ['alpha', 'beta']
8// (or maybe some other order, keys are unordered).
1let person = {
2 firstname: 'John',
3 lastname: 'Doe'
4}
5
6console.log(person.firstname);
7// expected output: "John"
8
9delete person.firstname;
10
11console.log(person.firstname);
12// expected output: undefined
1myObject = {
2 "key": "value"
3}
4
5Object.keys(myObject); // get array of keys
1myObject = {
2 "key": "value",
3 "key2":"value2"
4}
5Object.keys(myObject);
6//console.log(Object.keys(myObject)) = ["key", "key2"]
1const object1 = {
2 a: 'somestring',
3 b: 42,
4 c: false
5};
6
7console.log(Object.keys(object1));
8// expected output: Array ["a", "b", "c"]
1var buttons = {
2 foo: 'bar',
3 fiz: 'buz'
4};
5
6for ( var property in buttons ) {
7 console.log( property ); // Outputs: foo, fiz or fiz, foo
8}