Skip to content

Commit

Permalink
js 31 Object.keys, values, entries end
Browse files Browse the repository at this point in the history
  • Loading branch information
NazarikSenpai committed Jun 4, 2023
1 parent 96bf927 commit aab19a3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
37 changes: 37 additions & 0 deletions JavaScript/3_Data_Types/js_31_keys_values_entries/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

let obj = {
name: 'Nazariy',
age: 20,
gender: 'male',
address: {
street: '123 Main St',
city: 'New York',
state: 'NY',
},
phone: '555-555-5555',
email: 'kenaa@example.com',
password: 'password',
role: 'admin',
[Symbol('isOnline')]: true,
[Symbol('isRunning')]: true,
};

console.log(Object.values(obj));
console.log(Object.keys(obj));
console.log(Object.entries(obj));

console.log(Object.getOwnPropertySymbols(obj)); //повертає всі ключі символи
console.log(Reflect.ownKeys(obj)); // повертає усі ключі

let prices = {
banana: 1,
orange: 2,
meat: 4,
};

let doublePrices = Object.fromEntries(
Object.entries(prices).map((entry) => [entry[0], entry[1] * 2])
);

console.log(doublePrices);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

let salaries = {
John: 100,
Pete: 300,
Mary: 250,
};

function salariesSum(salaries) {
return Object.values(salaries).reduce((sum, salary) => sum + salary, 0);
}

function count(obj) {
return Object.keys(obj).length;
}

console.log(salariesSum(salaries));

console.log(count(salaries));

0 comments on commit aab19a3

Please sign in to comment.