How to correctly filter an array of objects in JavaScript?

I have a function that I have done to filter objects in a main array. This consists of getting the results in separate objects (all objects in the main array) and then with Object.keys (obj) .some () what I do is to get all the values ​​of the keys of the objects and with obj[key].includes (searchKey) I check if a value includes the search term (searchkey). Look at the code.

The problem:

The disadvantage is that only the specific term of a single object comes back to me, it means:

  • If I look for the term "Doc" I return the two expected objects in the returned array because the corresponding key values ​​match the search term.

  • If I look for the term "document" I've returned the expected array with a single object because it's specific term and finds only one result because it only fits a value.

  • BUT: If I look for the term "Docs" or a term that does not match (taken into account "Docs" if it is an existing value) I get the following error:

    obj[key].includes is not a function.

The code:

Change search values ​​(docs, document, no) to observe the error in the console.

NOTE: You can see how the main array is structured in the code.

// main table

var dictionary = [
    "name": "document",
    "classes" : {
      "getElementById": "getElementById()",
       "getElementsByClassName": "getElementsByClassName"
    "name": "docs",
    "classes": "holo"
    "name": "null",
    "classes": "null"

// function

filterIt function (arr, searchKey) {
back arr.filter (function (obj) {
returns Object.keys (obj) .some (function (key) {
back obj[key].includes (searchKey);

// LOG

// Edit the string to find another term.

console.log (filterIt (dictionary, "docs"))


At first glance, it seems as if the value did not exist, but when checking a log of obj[key] in some () I can see that all key values ​​of all objects are printed. What makes me think, Can I miss a loop or something?

Thank you so much.