krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.05k stars 766 forks source link

Get specific object by refIndex #480

Closed Abdullah-Softagics closed 3 years ago

Abdullah-Softagics commented 4 years ago

hi i am having an issue in retrieving a single object. for example i have an array of object which i give to

new Fuse(data)

now i search for a string "foo" in fuse.search() and get results using this

search_results = fuse.search(value);

result is like this in console.log();

[
0: Object { item: {…}, refIndex: 273 }
1: Object { item: {…}, refIndex: 1556 }
2: Object { item: {…}, refIndex: 4468 }
3: Object { item: {…}, refIndex: 8869 }
4: Object { item: {…}, refIndex: 10008 }
length: 5
]

now i want to get a single record from this array using refIndex. is there something like this

result = fuse.getObjectByIndex( refIndex )

??

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

sn3p commented 2 years ago

I think you can do this:

result = results.find(r => r.refIndex === 123);