lets say we received an object from an api response which contains some sensitive data
const userData = {
name:"Rick Sanchez",
email:"ricksanchez@getSchwifty.com"
address :" Dimension C-137",
sensitiveInfo:"wubba lubaa dub dub",
secretportalkey:"ABCDEF"
}
Now we want to pass it to some third party api but we dont want to pass the sensitiveInfo and secretPortal key to the Api
So, How do we remove that from the Object ?
Simple, just use the power of destructuring
const {sensitiveInfo,secretportalkey,...notSoSensitiveData} = userData
/* Now our notSoSensitiveData will contain all the properties except the ones which
are destructured
*/
console.log(notSoSensitiveData)
/* {
name:"Rick Sanchez",
email:"ricksanchez@getSchwifty.com"
address :" Dimension C-137",
}
*/
Top comments (0)