fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. // your code goes here
  5. const indata = [{
  6. id: 'M1',
  7. description: 'Lorem description',
  8. fields: [{
  9. name: 'field_1',
  10. value: 'Lorem value 1'
  11. }]
  12. }]
  13.  
  14. function transform(d) {
  15. const obj = {
  16. 'id': d.id,
  17. 'description': d.description
  18. };
  19.  
  20. for (let f of d.fields) {
  21. obj[f.name] = f.value
  22. }
  23.  
  24. return obj;
  25. }
  26.  
  27. console.log(indata.map(transform));
Success #stdin #stdout 0.09s 36048KB
stdin
Standard input is empty
stdout
[ { id: 'M1',
    description: 'Lorem description',
    field_1: 'Lorem value 1' } ]