Home » Javascript » Change object keys and value

Change object keys and value

Posted by: admin August 19, 2018 Leave a comment

Questions:

I have this array of objects from an api:

"use strict";

var data = [{
  "OPEN COVER (YES or NO)": "YES"
}, {
  "OPEN COVER (YES or NO)": "NO"
}, {
  "OPEN COVER (YES or NO)": "YES"
}];
var result = [];

data.map(function (item) {
  var fixed = {};
  var keys = Object.keys(item);
  keys.map(function (key) {
    if (key === 'OPEN COVER (YES or NO)') return fixed['open_cover'] = item[key];
  });
  result.push(fixed);
});
console.log(result);
Answers: