You have an array of objects what you want to do is map through them and return specific key value pairs in a new array.
The Functions Code SS

1. For example you have specific keys array

2. The JSON Object you want to manipulate

3. Result the mapped JSON Objects

const visibleColumnFields = ['LicencePlate', 'car', 'CarAttributes', 'ReservationStatus', 'ReservationType', 'CustomerGroupName'];
// The original json objects
let rows = [{
"LicencePlate": "ZPL 524",
"car": "Opel Corsa",
"CarAttributes": "Z",
"ReservationStatus": "İptal Edildi",
"ReservationType": "Yıllık İç Müşteri",
"CustomerGroupName": "Dev Test Technology",
"CompanyName": "İş Geliştirme Müdürlüğü",
"Zimmet": "Petor Petor ",
"LocationName": "Test Company Location",
"EndDateTime": "28.04.2022 00:00",
"RentDays": "1 Gün",
"TotalPrice": "350.00",
"CurrencyType": "Lira",
"CurrencySymbol": "₺",
"TotalPriceByCurrency": "350.00",
"CurrencyRate": "1"
}];
// Mapping over the objects
let retwriteRow = rows.map( function (e) {
return Object.keys(e).filter((key) => visibleColumnFields.includes(key)).reduce( (cur, key) => {
return Object.assign(cur, {[key] : e[key]})
},{})
});
Top comments (1)
Thank you