-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js 31 Object.keys, values, entries end
- Loading branch information
1 parent
96bf927
commit aab19a3
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
JavaScript/3_Data_Types/js_31_keys_values_entries/script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
19 changes: 19 additions & 0 deletions
19
JavaScript/3_Data_Types/js_31_keys_values_entries/tasks/salariesSum.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |