how to filter and return key-value pairs if key is not equal to "targetTime". I have tried with:
const obj = {
"name": "Rima Biswas",
"email": "rima.biswas@test.com",
"station": "Agartala",
"targetTime": { "startDate": "2022-02-01T18:30:00.000Z", "endDate": "2022-02-28T18:30:00.000Z" }
};
const entries = Object.entries(obj).filter(([key, value]) => key != "targetTime ");
console.log(entries);
Either
const requiredData = Object.entries(obj).filter(([key, value]) => key !== "targetTime")
Or
const {targetTime, ...restData} = obj;
const requiredData = restData;
Use the code below:
let obj = {
"name": "Rima Biswas",
"email": "rima.biswas@test.com",
"station": "Agartala",
"targetTime": {
"startDate": "2022-02-01T18:30:00.000Z",
"endDate": "2022-02-28T18:30:00.000Z"
}};
Object.fromEntries(Object.entries(obj).filter(([key]) => key !== 'targetTime'));