Skip to content

question: how to remove property from object #136

@bhainesva

Description

@bhainesva

I'd like to remove a property with a specific name from an object. For example given:

const x = {
  numprop: 3, // important comment about the numprop
  filter: {
     test: "hi",
  },
  objprop: {
     a: "a"
  },
}

I'd like to remove the filter property and end up with:

const x = {
  numprop: 3, // important comment about the numprop
  objprop: {
     a: "a"
  },
}

My first attempt was grasp 'obj.props[key=#filter]' -R '' but this leaves an extra comma where the property was removed.

I also tried grasp 'obj! > prop[key=#filter]' -R '{\n{{.props[key!=#filter] | join ",\n" }}\n}' which does work, but since it rewrites the whole object it also removes any comments on the parts of the object I want to keep. Is there an alternative to avoid this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions