I have an object where I store words, their pronunciation, type, description usage and number of favorites.
Words: {
word: string,
pronunciation: string,
type: string,
description : string,
usage: string,
favorites: number
}[] = [];
First I get the Words out of local storage with and assign them to a new object.
Then I sort those words by favorites so the word with most favorites is top on the list.
this.storage.get('words').then((val) => {
this.Popular = val;
this.Popular.sort(function (a,b) {return b.favorite - a.favorite});
}
When the user clicks on the word I want to get the index of that word in the original unsorted object.
So I get the original object again out of the storage.
Then I'm trying to get the original id of the word with indexOf but I always get -1 despite the selected word being in the original object.
this.storage.get('words').then((val) => {
this.Words = val;
var index = this.Words.indexOf(selectedWord);
console.log(index);
}
selectedWord is a word selected from the sorted list:
Word: {
word: string,
pronunciation: string,
type: string,
description : string,
usage: string,
favorites: number
}
What am I doing wrong? How can I get the index of the selected word from the original unsorted object?