Title: Center String in JavaScript - Runnable Code Snippet
Open Graph Title: Center String in JavaScript - Runnable Code Snippet
X Title: Center String in JavaScript - Runnable Code Snippet
Description: Center a string within a given width by padding with spaces. Runnable JavaScript snippet with live execution.
Open Graph Description: Center a string within a given width by padding with spaces. Runnable JavaScript snippet with live execution.
X Description: Center a string within a given width by padding with spaces. Runnable JavaScript snippet with live execution.
Keywords:
Opengraph URL: https://tempercode.dev/snippets/center-string-javascript
Domain: tempercode.dev
{"@context":"https://schema.org","@type":"SoftwareSourceCode","name":"Center String","description":"Center a string within a given width by padding with spaces.","programmingLanguage":"JavaScript","text":"const padding = Math.max(0, width - str.length);\nconst left = Math.floor(padding / 2);\nreturn ' '.repeat(left) + str + ' '.repeat(padding - left);"}
| theme-color | #0c0d12 |
| color-scheme | dark |
| author | Temper |
| creator | Temper |
| publisher | Temper |
| og:image | https://tempercode.dev/og-image.png |
| og:type | article |
| twitter:card | summary_large_image |
| twitter:image | https://tempercode.dev/og-image.png |
Links:
Viewport: width=device-width, initial-scale=1