'JavaScript: filter object entries by key
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": "[email protected]",
"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);
Solution 1:[1]
Use the code below:
let obj = {
"name": "Rima Biswas",
"email": "[email protected]",
"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'));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Paul Robert |
