Answers for "js string ellipsis"

0

javascript cut string if too long

if (string.length > 25) {
  string = string.substring(0, 24) + "...";
}

//or 

function truncate(str, n){
  return (str.length > n) ? str.substr(0, n-1) + '…' : str;
};

//or with CSS

p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

//or with replace

short = long.replace(/(.{7})..+/, "$1…");
Posted by: Guest on July-22-2020
-1

ellipses in js

//Example: 
const numbers1 = [1, 2, 3, 4, 5];
const numbers2 = [ ...numbers1, 1, 2, 6,7,8]; 
// this will be [1, 2, 3, 4, 5, 1, 2, 6, 7, 8]
Posted by: Guest on February-04-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language