'Why is my array.find and array.filter returning empty
I have an Array that looks like this
resultList: any[];
this.resultList = [
{
"id": "14e6f101-f8e8-4914-930f-cbba7a9c5328",
"value": "Dream Inc."
},
{
"id": "9a16c1c0-68f3-498a-b968-61849ccc2a21",
"value": "Dressing, Inc. ABC LOREBOX SERVICES"
},
{
"id": "919b3cdb-c5fb-40c8-b88f-6c7f44f8446f",
"value": "Dresson-Brand Company"
}
]
I am having a hard time trying to retrieve the second item (index 1) by using the value. I can get the other two items by value but the second item returns undefined
code I am using
search(value: any) {
//value coming in
//Dressing, Inc. ABC LOREBOX SERVICES
console.log('*** value to search ***', value);
var foundObj = this.resultList.find(p => p.value == value);
console.log('*** foundObj ***', foundObj);
}
foundObj comes back empty and same results when I do a filter. Any idea's what is wrong with that string that it can't be found? It seems I can get any other string (this is a dynamic array) but this one.
Solution 1:[1]
The issue came from the dataList I was using. In the element I was missing the 'value' attribute. Once I added that the spaces were no longer removed and my filtering was able to pick it up.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DeepToot |
