0

I'm using fuzzy module with node but I have long JSON Array contain object. I need matched object whole. Like

link of module Fuzzy Modules

var list = [
  {rompalu: 'baconing', zibbity: 'simba'}
, {rompalu: 'narwhal' , zibbity: 'mufasa'}
, {rompalu: 'a mighty bear canoe', zibbity: 'saddam hussein'}
];

I have above list of JSON Array and if I pass word narwhal than It's return only matched words in Array but I need array of matched object. output like :

[
   {rompalu: 'narwhal' , zibbity: 'mufasa'}
]
Gunjan Patel
  • 2,342
  • 4
  • 24
  • 45

1 Answers1

1

There seem to be various options.

  • Filter the list manually using fuzzy.test():

    var results = list.filter(function(obj) {
        return fuzzy.test('narwhal', obj.rompalu);
    });
    
  • Extract the "originals":

    var options = { extract: function(el) { return el.rompalu; } };
    var results = fuzzy.filter('narwhal', list, options).map(function(r) {
      return r.original;
    });
    
robertklep
  • 198,204
  • 35
  • 394
  • 381