object_map.js 409 B

1234567891011121314151617181920
  1. let obj = {
  2. name: "Иван",
  3. age: 17
  4. }
  5. const map = (obj, func) => {
  6. let newObj = {};
  7. for (const [key, value] of Object.entries(obj)) {
  8. obj = Object.assign(newObj, func(key, value));
  9. }
  10. return obj;
  11. }
  12. const mappedObject = map(obj,(key,value) =>{
  13. let result = {};
  14. result[key+"_"] = value + "$";
  15. return result;
  16. });
  17. console.log(mappedObject); // { name_: 'Иван$', age_: '17$' }