1var person={
2 "first_name":"Harry",
3 "last_name":"Potter",
4 "age":14
5};
6var personSize = Object.keys(person).length; //gets number of properties (3)
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"]
1var myObj = {no:'u',my:'sql'}
2var keys = Object.keys(myObj);//returnes the array ['no','my'];
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}
1const object1 = {
2 a: 'somestring',
3 b: 42,
4 c: false
5};
6
7console.log(Object.keys(object1));
8