Search in Array<String> returns indexes instead of items
See original GitHub issueHello, I used Live Demo page to check a search in flat array:
const list = [
{ value: "85626400800" },
{ value: "81323902061" },
{ value: "8079842032" },
{ value: "7825731309" },
{ value: "9492224473" },
{ value: "81323902062" },
{ value: "71509915863" },
{ value: "84718105204" },
{ value: "81323902013" },
{ value: "80487910890" },
]
var options = {
shouldSort: true,
tokenize: true,
matchAllTokens: true,
threshold: 0,
location: 0,
distance: 0,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: [
"value"
]
};
var fuse = new Fuse(list, options); // "list" is the item array
var result = fuse.search("804");
/* SEARCH RESULTS */
[
{
"value": "80487910890"
}
]
But when I try to search by flat list it returns indexes instead of items
const list = [
"85626400800",
"81323902061",
"8079842032",
"7825731309",
"9492224473",
"81323902062",
"71509915863",
"84718105204",
"81323902013",
"80487910890",
]
// Options without a "key" property
var options = {
shouldSort: true,
tokenize: true,
matchAllTokens: true,
threshold: 0,
location: 0,
distance: 0,
maxPatternLength: 32,
minMatchCharLength: 1,
};
var fuse = new Fuse(list, options); // "list" is the item array
var result = fuse.search("804");
/* SEARCH RESULTS */
[
9
]
Looks like issue is here — https://github.com/krisk/Fuse/blob/master/src/index.js#L136 Why is that?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:8
Top Results From Across the Web
Search Array Elements For Substring and return index
I am trying to search through each element in an Array to find if it contains a substring. If it does I want...
Read more >Four Methods to Search Through Arrays in JavaScript
Learn about four approaches to searching for values in arrays: includes, indexOf, find, and filter methods.
Read more >Indexed collections - JavaScript - MDN Web Docs - Mozilla
The indexOf() method searches the array for searchElement and returns the index of the first match. const a = ['a', 'b', ...
Read more >5. Working with Arrays and Loops - JavaScript Cookbook [Book]
Arrays in JavaScript are zero-based, which means the first element index is zero, ... It returns a string with all of the array...
Read more >array_search - Manual - PHP
array_search — Searches the array for a given value and returns the first ... values, use array_keys() with the optional search_value parameter instead....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s probably just a weird decision that was made a long time ago. Not so hard to get around:
I wonder if it’s possible to type correctly? Maybe with conditional types.