Removing a part

My issue is I want to remove a part which is actually a background.

Suppose this is how I added a part

scope.gj(go.Part, // this Part is not bound to any model data
layerName: “Background”, position: new go.Point(0, 0),
selectable: false, pickable: false
scope.gj(go.Picture, {
source: img.src,
//width: scope.totalDiagramWidth,
//height: scope.totalDiagramHeight
new go.Binding(“width”, “widthOfCanvas”),
new go.Binding(“height”, “heightOfCanvas”)

Now I want to remove it
How is it possible please?

If that was the only Part that you added, it should be the value of

By the way, scope.gj is very suspicious. You really should be using go.GraphObject.make.

@walter Make total sense to me
But I am adding a bunch of parts on the flow
How can I remove a specific part?
Is there any way I can search a part by name or something like this and then remove it

Of course you can keep references to the Parts that you add in JavaScript.

Or I suppose you can give them GraphObject.names as you add them. Later you can search in the collection for the Part with the name that you care about.

Exactly that is what I am digging into. I am new with gojs so struggling a little
I am looking for a best iteration function that can return me a part with a particular name.
Suppose the name of the part is “test” that I want to remove
How I can search for a part with name “test”?
I know gojs have some functions like findPartForData and findPartForKey but none of them are working .

function findPart(name) {
  var it =;
  while ( {
    if ( === name) return it.value;
  return null;

it worked thanks Walter