📌  相关文章
📜  javascript 如何获取字符串的中间字母 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:56.247000             🧑  作者: Mango

代码示例1
function extractMiddle(str) {

        var position;
        var length;

        if(str.length % 2 == 1) {
            position = str.length / 2;
            length = 1;
        } else {
            position = str.length / 2 - 1;
            length = 2;
        }

        return str.substring(position, position + length)
    }

    console.log(extractMiddle("handbananna"));