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).
1// Object Entries returns object as Array of [key,value] Array
2const object1 = {
3 a: 'somestring',
4 b: 42
5}
6Object.entries(object1) // Array(2) [["a", "something"], ["b", 42]]
7 .forEach(([key, value]) => console.log(`${key}: ${value}`))
8// "a: somestring"
9// "b: 42"
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"]
1document.inputDiv.addEventListener('keyup', (e) => {
2 console.log(e.key);
3});
4
5// Typing 'hello world' will log --> 'h' 'e' 'l' 'l' 'o' ' ' 'w' 'o' 'r' 'l' 'd';
1const object1 = {
2 a: 'somestring',
3 b: 42
4};
5
6for (let [key, value] of Object.entries(object1)) {
7 console.log(`${key}: ${value}`);
8}
9
10// expected output:
11// "a: somestring"
12// "b: 42"
13// order is not guaranteed
1var myObj = {no:'u',my:'sql'}
2var keys = Object.keys(myObj);//returnes the array ['no','my'];