user6112430
user6112430

Reputation:

Implement filter functionality using react.js

First of all please have a look here.

[http://codepen.io/webmaster444/pen/yOxrNa][1]

Here you could notice that it searches names start with input but not whole names.

For instance if you input touch then it returns no value. I want to return iPod touch. What can I do?

Upvotes: 0

Views: 72

Answers (1)

Marco Scabbiolo
Marco Scabbiolo

Reputation: 7449

In line 10 change

if (item.name.toLowerCase().indexOf(input)) {

to

if (item.name.toLowerCase().indexOf(input) === -1) {

Don't rely on truthy or falsy values, do the proper conversion and use the === operator every time you have the slightest doubt on how a value such as an numeric value will be converted into boolean.

Upvotes: 1

Related Questions