简体   繁体   English

JavaScript数组reduce()累加器为空

[英]JavaScript array reduce() accumulator is empty

I am splitting a word and converting each individual element to morse code. 我正在拆分一个单词,并将每个单独的元素转换为莫尔斯电码。 However, the return value is empty. 但是,返回值为空。 Not sure what I am doing wrong here. 不知道我在做什么错。

        wordTransformed = word.split("").reduce((total, letter) => {
            currentLetterIndex = alphabet.indexOf(letter);
            total + morseAlphabet[currentLetterIndex];
            return total
        },"");

        console.log(wordTransformed);
total + morseAlphabet[currentLetterIndex];

You're looking for 您正在寻找

total += morseAlphabet[currentLetterIndex];

https://www.w3schools.com/js/js_assignment.asp https://www.w3schools.com/js/js_assignment.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM