0
I’m trying to transform an array with strings inside in lowercase using toLowerCase, but it doesn’t seem to work with an array, but only with a string... How do I fix it?
items: Array<{tag: string[], image: string, page}>;
toggledItems() {
this.items = [
{
tag: ['exemplo1','exemplo2'],
image: '../../assets/imgs/exemplo/ccc.jpg',
page: Ex1Page,
},
{
tag: ['exemplo4', 'exemplo5', 'exemplo6'],
image: '../../assets/imgs/exemplo/ci.jpg',
page: Ex1Page,
}
];
}
In the code below is where I add the "tag" array that is inside the "items" array. But it doesn’t work.
if (val && val.trim() != '') {
this.items = this.items.filter((item) => {
return (item.tag.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
Thank you for your reply. But when I use the code you gave me, it transforms the strings within the "tag" array into true booleans, hence the res.toLowerCase() function accuses it does not exist...
– JPTS
But what is turning the tags into boolean? Surely there is something else in your code that is doing this, I tested here with this your object and was quiet.
– thismarcoantonio
After some tests I realized that this stretch ". indexof(val.toLowerCase()) > -1" is causing the transformation into Boolean. But I don’t understand the reason... (this excerpt transforms what is written in the Archbar in Livingcase, so it is essential)
– JPTS
It is returning boolean and is normal, you are asking if the Index of the value is greater than -1 (trick to know if it exists). I think I would have no problem always making the value lowercase, even if it was not, or would have?
– thismarcoantonio
Eventually I realized the function ". indexof(val.toLowerCase()) > -1" is adding a Boolean at the end of the "res" array and acting very different from how it should...
– JPTS
No, it’s actually acting exactly the way it should. Why is that? index > -1? If yes, true, if not, false. Because you need this index?
– thismarcoantonio
It should indicate the items that will appear in the list during the search. Example: I write "example" in Archbar and it shows both items, but if I write "exemplo4" it shows only the second item. At least that’s what’s supposed to happen, but I’m having a really hard time fixing this. I’m sure there is a simple solution, but I’m beginner in programming.
– JPTS
Follow the plunker with the solution: http://plnkr.co/edit/reGXZfiyBBY7GXZT81hG
– thismarcoantonio
Thank you for the explanations and for the attention you are giving to my problem friend. I tested the code you sent me and it works just as I could make the other one work. But not the way it should. The concept is that when typing the letters, the images will appear with the corresponding letter tags until only the specific word remains. In that code ai the corresponding image only appears when a tag word is COMPLETELY written and equal to the array... For the user this is somewhat bad in the search category.
– JPTS
I just finished editing the plunker and the answer, I think this will be enough.
– thismarcoantonio
IT WORKED! Dude, you’re awesome! I know it’s something simple, but for me who am starting, making anything work is an immense joy. Make sure I remember the help and attention you gave me. Thank you!
– JPTS
Anything just call, I’m happy to help
– thismarcoantonio