script

Mask an object's properties with an example object

universalBeginner

About this Snippet

This snippet allows you to apply a mask, or filter, to an object using an example object. So if you have the object:

{
   person: \{
    name: "john doe",
    email: "john@doe.com",
    phone: "555-555-5555",
    social: "555-55-5555",
    kids: ["sally","michelle"]
   \}
  }

But you only want to return their name and email, you provide the script with a filter object like:

{
   person: \{
    name: true,
    email: true
   \}
  }

And it will return:

{
   person: \{
    name: "john doe",
    email: "john@doe.com"
   \}
  }

The snippet includes an additional "demo" script that returns a sample set of data that you can use to test how it works.

You'll only need the 2nd script in the snippet to perform the actual object filter/mask.

See it in action