7
7
75db772019-11-10 11:43:13
JavaScript
75db77, 2019-11-10 11:43:13

How to add a method to an object property if the property name consists of two words?

I have this line:

return data.filter(n => n.dori.toLowerCase().includes(search));

doriis a property of the object
But instead of this property, I need to write a property whose name consists of two words carColorID.code
. How should this line look then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Somewhere Intech, 2019-11-10
@john36allTa

Partial search (any occurrence of the substring search in the string carColorId.code ):

export function searchFilter(search, data) {
  return data.filter(n => n.carColorId.code.toLowerCase().includes(search));
}

Partial search (occurrence of the substring search in the string carColorId.code , but the search is performed from the beginning of the string carColorId.code ):
export function searchFilter(search, data) {
   let pattern = new RegExp("^"+search, "i");
   return data.filter( n=> pattern.test(n.carColorId.code) );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question