将新对象添加到 map 函数中的 json 数据中

Add new objet to the json data inside in map func

大家好,我需要确定该字符串中最常用的三个词。我想用 JSON 对象来做到这一点。实际上,我之前尝试过使用hashMap函数,但我无法更新单词的值。

我该怎么做,这是我的错吗?

const text = "  //wont won't won't blue blue yellow won't ";
const wordList = text.split(' ').filter(String);

const obj = {}

wordList.map(word => (
  obj = { 
          ...obj, {
        word: word,
        count: +1
      }
  }
)

不应该是这样的吗:

wordList.map(word => (
  if (! (word in obj)) {
    obj[word] = {
      word,  // not really necessary...?
      count: 0
    }
  }
  obj[word].count += 1;
)