SOURCE

function trim(str) {
	if (str === null) {
		return "";
	}
	let start, end;
	for (let i = 0; i < str.length; i++) {
		if (str[i] !== " ") {
			start = i;
			break;
		}
	}
	for (let i = str.length - 1; i >= 0; i--) {
		if (str[i] !== " ") {
			end = i;
			break;
		}
	}

	return str.slice(start, end + 1);
}
console.log(trim(' abc '));
console.log(123);
console 命令行工具 X clear

                    
>
console