Copy a string to the clipboard

tipjs,object

Copy a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).

const copyToClipboard = str => {
  const el = document.createElement('textarea');
  el.value = str;
  el.setAttribute('readonly', '');
  el.style.position = 'absolute';
  el.style.left = '-9999px';
  document.body.appendChild(el);
  const selected =
    document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
  el.select();
  document.execCommand('copy');
  document.body.removeChild(el);
  if (selected) {
    document.getSelection().removeAllRanges();
    document.getSelection().addRange(selected);
  }
};
//Use
copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.

Có thể bạn đã miss một số snippets code

Clone Objects in JavaScript

3 Ways to Clone Objects in JavaScript

Remove array of objects from another array of objects

Remove array of objects from another array of objects

Kiểm tra định dạng email bằng Javascript

Kiểm tra định dạng email bằng Javascript

Spread Operator for Objects

Using the spread operator during an Object declaration will assign the properties of the referenced Object to the new Object.

Đếm số phần tử trong mảng JavaScript

Đếm số lần xuất hiện của các phần tử trong mảng JavaScript