JavaScript

trim/split/replace in JavaScript

JavaScriptStringsstring methodsbeginner

What this snippet does

replace only replaces the first match — use replaceAll or a global regex to replace every occurrence.

Expected output

hello world
hello world  
[ 'a', 'b', 'c', 'd' ]
a | b | c | d
baz bar foo
baz bar baz

Why practise typing this

Typing strings code builds muscle memory for the symbols and indentation JavaScript uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More JavaScript practice

Browse all JavaScript snippets →