I'm trying to make language learn app and i have a problem. I have class "Word"
class Word {
constructor(englishWord, polishWord){
this.englishWord = englishWord
this.polishWord = polishWord
this.displayTranslation = () =>{
console.log(`${englishWord} = ${polishWord}`)
}
}
}
and lots of objects like
const intimate = new Word('intimate', 'intymny/prywatny')
const insurance = new Word('insurance', 'ubezpieczenie')
and I honestly don't have idea how to push all objects into one array. Can I use 'foreach' on every class object? Or is there a better solution for this?
WordManagerclass that is responsible for building and recording words, a laclass WordManager { constructor() {} create(word, mapping) { let w = new Word(word, mapping); this.words.push(w); return w; }, or better yet, why not make a word dictionary instead of using individual word instances? Especially given that JS objects are already dictionaries:const words = {}; words["intimate"] = "intymny/prywatny";and take it from there?