How to create search /Filter In JavaScript ?

String List Search

const search = ()=>{

const words = [‘spray’, ‘limit’, ‘elite’, ‘exuberant’, ‘destruction’, ‘present’,”dd” ,”ad”];

const filterList =(dataArray, searchingValue)=> {

return data.filter(name => name.toLowerCase().search(query.toLowerCase()) !== -1);

};

console.log(filterList(words,”d”));//[“destruction”, “dd”, “ad”]

console.log(filterList(words,”d”).sort());//[“ad”, “dd”, “destruction”]

}

Search by input String value length

const words = ['spray', 'limit', 'elite', 'exuberant','destruction',
'present'];
const result = words.filter(word => word.length > 6);
console.log(result);

other way

// search using keyword from array
var keywordToSearch = 'Arslan'; // word to search
var keyword = keywordToSearch.toLowerCase();
var names = [{id: 1, name: 'Aqib'}, {id: 2, name: 'Arslan'}];

//search keyword from names array by name
var searchResult = names.filter(word => word.name.toLowerCase().indexOf(keyword) > -1);
console.log(searchResult);
// expected output: > Array [Object { id: 2, name: "Arslan" }]

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response