javascript truncate string full word
const truncate = (str, max, suffix) => str.length < max ? str : `${str.substr(0, str.substr(0, max - suffix.length).lastIndexOf(' '))}${suffix}`;
// Example
truncate('This is a long message', 20, '...');
Also in JavaScript:
- db.json
- how to know which button clicked in javascript
- componentDidUpdate
- what is package.json
- resizable in jquery interaction
- how to create a component in react native
- javascript in integer tostring
- hide and show in angular 8
- object traversal javascript
- recuperer une image dans la base de données avec angular
- Build JavaScript Objects
- mongoose if empty string is provided use default
- Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class
- date masking javascript to not allow /
- javascript extend object
- delete backspace on string js
- jquery watch checkbox change
- react hook s
- vuejs filter array by dates
- how to remove duplicates in array in javascript
- set readonly in javascript
- js map value in range
- how to make an express server
- new features of angular 11