Open this example in the interactive library
Source code
const words = ["studio", "study", "student"];
let prefix = words[0];
while (prefix && !words.every((w) => w.startsWith(prefix)))
prefix = prefix.slice(0, -1);
console.log(prefix);
Sample output
stud
