1234567891011121314151617181920 |
- let obj = {
- name: "Иван",
- age: 17
- }
- const map = (obj, func) => {
- let newObj = {};
- for (const [key, value] of Object.entries(obj)) {
- obj = Object.assign(newObj, func(key, value));
- }
- return obj;
- }
- const mappedObject = map(obj,(key,value) =>{
- let result = {};
- result[key+"_"] = value + "$";
- return result;
- });
- console.log(mappedObject); // { name_: 'Иван$', age_: '17$' }
|