js判断字符串是不是回文字符串

var test1 = 'n333oon';
    var test2 = '';
    test1_len = test1.length - 1;
    for (let i = test1_len; i >= 0; i--) {
        test2 += test1[i]
    }

    var value = 0;
    for (let i = 0; i < test1.length; i++) {
        if (test1[i] === test2[i]) {
            value += 1;
        } else {
            console.log('不是回文');
            break;
        }
    }
    if (value == test1.length) {
        console.log('是回文')
    }

你可能感兴趣的:(js)