Untitled
unknown
plain_text
4 years ago
784 B
10
Indexable
let allowedFields=["firstName", "email", "_id"];
let arrOfUsers=[
{
_id:"abc",
firstName:"Shekhar",
lastName:"Kadam",
email:"[email protected]",
createdAt:"67"
},
{
_id:"def",
firstName:"Harsh",
lastName:"Singh",
email:"[email protected]",
createdAt:"67",
npo:90
},
{
_id:"ghi",
firstName:"sushant",
lastName:"singh",
email:"[email protected]"
},
]
let newArray=[];
arrOfUsers.map((eachUser)=>{
const userKeys=Object.keys(eachUser);
let newObj={};
userKeys.filter((eachKey)=>allowedFields.includes(eachKey)).map((newKey)=>{
newObj[newKey]=eachUser[newKey];
});
newArray.push(newObj);
});
console.log(newArray)Editor is loading...