How to split a string in half with JavaScript

1 Answer

0 votes
const str = "c# c javascript c++ python go";
const center = parseInt(str.length / 2);

const firstHalf = str.substring(0, center);
const secondHalf = str.substring(center);

console.log(firstHalf);
console.log(secondHalf);




/*
run:

"c# c javascrip"
"t c++ python go"

*/

 



answered Aug 10, 2023 by avibootz
...