JSFiddle - React, Tailwind, and code Playground

by Prathameshsb

HTML

<div class="copy-container">
  <input type="text" value="Hello, Clipboard!" id="copyText" readonly>
  <button onclick="copyToClipboard()">Copy</button>
</div>

CSS

input {
    border: none;
}

button {
    cursor: pointer;
}

JavaScript

const arr = ['one','two','three','four'];

[arr[0], arr[3]] = [arr[3], arr[0]];

console.log(arr);

const x = 'constructor';

const obj = {
	fn: 'john',
  ln: 'pav'
}

function copyToClipboard() {
    // Select the text input
    const copyText = document.getElementById("copyText");
    copyText.select();

    // Copy the selected text to the clipboard
    document.execCommand("copy");

    // Deselect the text input
    copyText.setSelectionRange(0, 0);

    // Display a message (you can customize this part)
    alert("Copied to clipboard: " + copyText.value);
}