How delete or remove a component of an GameObject?

I am trying to remove this component.

I’ve tried

Component.Destroy(script);
this.gameObject.Component.Destroy(script);
etc etc. I am using JavaScript

Also, while I am at this how do you add one? It said it can’t find my script to add as a component.

simply use Destroy() function.

// Kills the game object
	Destroy (gameObject);
	// Removes this script instance from the game object
	Destroy (this);
	// Removes the rigidbody from the game object
	Destroy (rigidbody);
	
	// Kills the game object in 5 seconds after loading the object
	Destroy (gameObject, 5);
	// When the user presses Ctrl, it will remove the script 
	// named FooScript from the game object
	function Update () {
		if (Input.GetButton ("Fire1") && GetComponent (FooScript))
			Destroy (GetComponent (FooScript));
	}

remove unity gameobject

Destroy(GetComponent(myScript));

If you wrote a script you did not have to say GetComponent twice. Because it’s already defined! :wink:

Example:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExampleClass : MonoBehaviour 
{
        public ExampleScript exp;
        
        void Start ()
        {
              exp = GetComponent<ExampleScript>();
        }

        void Update ()
        {
               Destroy(exp);
        }
}

Check the link below.The blog teaches the way to create a gameobject,add components,remove componenets and deleting gameobject on runtime.