How to split a string in half with Node.js

1 Answer

0 votes
const str = "c# c node.js 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 node.js 
c++ python go

*/

 



answered Aug 10, 2023 by avibootz
...