var str = 'i like code and writing code makes me feel charming'; var array = str.split(" ").reduce((prev, next) => (prev[next]++ || (prev[next] = 1), prev), {})