Filter an Array based off user input string and menu dropdown items

Filter an Array based off user input string and menu dropdown items

Content Index :

Filter an Array based off user input string and menu dropdown items
Tag : javascript , By : user104292
Date : November 28 2020, 04:01 AM

it should still fix some issue I think checking the array as a truthy value instead of the length of the array was your biggest issue.
However, I also think this could be written more simply by moving the repeated code to functions and just running one filter. If you don't like ternary operators you can replace what I have with your if/if else clauses (don't forget the returns though).
const searchQuery = "ben";
const pattern = [];

const exercises = [
    name: "bench press",
    movement: ["push", "pull", "squat", "hinge"]
    name: "squat",
    movement: ["push", "pull", "squat", "hinge"]
    name: "squat",
    movement: ["squat", "hinge"]
    name: "pushup",
    movement: ["push", "pull", "squat", "hinge"]
    name: "pullup",
    movement: ["pull", "squat", "hinge"]
    name: "bent over row",
    movement: ["push", "pull", "hinge"]

const excerciseTest = (name, searchQuery) => {

return name.toLowerCase().includes(searchQuery.toLowerCase())

const patternTest = (movement, pattern) => {
  return movement.some(movement => {
    return pattern.some(pattern => pattern === movement)
const filteredExercises = exercises.filter(excercise => {

    // if (searchQuery && pattern.length > 0)
  return (searchQuery && pattern.length > 0)
    ? excerciseTest(excercise.name, searchQuery) && patternTest(excercise.movement, pattern)
    // else if (pattern.length > 0)
    : pattern.length > 0
    ? patternTest(excercise.movement, pattern)

    // else if (searchQuery)
    : searchQuery
    ? excerciseTest(excercise.name, searchQuery)
    : false


No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Setting menu items based on user input android

Tag : java , By : Ben Kohn
Date : March 29 2020, 07:55 AM
This might help you You were on the right track with the first attempt. You use invalidateOptionsMenu() to trigger a call to onPrepareOptionsMenu() where you implement your changes to the menu.
You need to return true from onPrepareOptionsMenu() in order for it to be displayed.
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_main_drawer, menu);    

    return true;

public boolean onPrepareOptionsMenu(Menu menu) {


    return true;
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
            android:title="Spell Book"

Filter Object Array values based on user input

Tag : javascript , By : Grant
Date : March 29 2020, 07:55 AM
like below fixes the issue You can use the function reduce and filter the data using the functions filter and indexOf.
This alternative uses the function Object.keys to be able to recover the desired key.
let data = {  Belgien: [{    code: "BRU",    name: "Bryssel",    aliases: "Bryssel,BRU,Belgien"  }],  Cypern: [{      code: "LCA",      name: "Larnaca",      aliases: "Larnaca,LCA,Cypern,Ayia Napa,Protaras,Fig Tree Bay,Larnaca"    },    {      code: "PFO",      name: "Paphos",      aliases: "Paphos,PFO,Cypern"    }  ]},
    userInput = "lar",
    filteredData = Object.keys(data).reduce((a, k) => {
      a[k] = data[k].filter(({name}) => name.toLowerCase().indexOf(userInput) > -1);
      return a;
    }, {});

.as-console-wrapper { max-height: 100% !important; top: 0; }

How to filter the entire array based on user input using filter in JavaScript ?

Tag : javascript , By : ranja
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I am trying to use a filter in javascript to search on an array. Following is my array:- , customerId is an integer - you need to cast to string, e.g.:
return `${items.customerId}`
let newRow = this.state.rows.filter(({customerId, customerName}) => 
  `${customerName || ''}`
let newRow = this.state.rows.filter(({customerId, customerName, auditorName}) => 
  [customerId, customerName, auditorName].some(field => 
    `${field || ''}`

Filter selectlist options based on user input while retaining items that were already selected

Tag : knockout.js , By : CookingCoder
Date : March 29 2020, 07:55 AM
I wish this help you Html Code , The problem is with the following line
// Default the list to include the selected items.
ko.utils.arrayPushAll(filteredList, _root.selectedEquipment());

How to achieve Dynamic Menu items list based on User Rights Array?

Tag : angular , By : fstender
Date : March 29 2020, 07:55 AM
this one helps. If I've understood right you want this to create a menĂ¹ that the user can see. So, in this example, the user will only see two entry named "Add Roles", and "Edit Roles", right?
Create a MenĂ¹ class like this :
export class MenuEntities {
   public state: string;
   public name: string;
   public target: boolean;
children: [
                state: 'add-roles',
                name: 'Add Roles',
                // target: true
                state: 'edit-roles',
                name: 'Edit Roles',
                // target: true
public menuEntities: MenuEntities[] = [];
// I let you do the logic to parse the json to this array.
<ul *ngFor="let entity of menuEntities">
   <li>States : {{entity.states}}</li>
   <li>Name : {{entity.name}} </li>
Related Posts Related QUESTIONS :
  • Customizing Material-UI Components with Styled-Components
  • Populate elements with class name using Javascript
  • How to execute promises in batches (first resolving 10, then next 10 and so on)
  • Maximo JS automation script: "importPackage" is not defined
  • How to surround selected text inside textarea with <em> on key combination CTRL+i?
  • Your configured registry does not support audit requests ~ On npm audit
  • What's the Angular equivalent of Vue <slot/>?
  • Iconify icon not updating when "data-icon" set with setAttribute()
  • Javascript newbie stuck with XMLHttpRequest return data
  • How to add obj to to state in my example Redux React
  • Loading "grunt-karma.js" tasks...ERROR >> SyntaxError: Unexpected identifier
  • Why do I get log is not defined
  • get the multiple index of the same string
  • How can I iterate over an Array object by using For IN or FOR OF
  • Launch local executable from web browser
  • How to prepare array of json objects to d3 hierarchical tree structure
  • VueJS - event emitted - show HTML before other calculations
  • Export SASS/SCSS variables to Javascript without exporting them to CSS
  • How to attach an event handler only once continuously
  • How to make button open a link in new tab in JavaScript?
  • Find range from the javascript object
  • How can I use my jQuery code as JavaScript?
  • How to show 5 images in a 2 row slider with bxslider
  • How to convert stream into variables in typescript
  • Three.js custom shader error on Chrome GL_INVALID_OPERATION: Active draw buffers with missing fragment shader outputs
  • My JavaScript doesn't work. How can I solve this problem?
  • Why is this async function is running synchronously?
  • Get updated variable from within react hook before return
  • I want to show all image preview but whenever I upload a new one the old one is gone
  • Would I be able to give access to specific electron APIs safely?
  • Why several clicks fire for each instance of a Class?
  • cant grab value from div using attr()
  • Make web service not accessible by browser?
  • Select DOM elements within template
  • How to customize angular ui-grid row background color?
  • Binding data in two respective $scope in AngularJS, how?
  • react put some props after import class
  • Variable is distributed among same components
  • switch class in jQuery/JavaScript for active/inactive state
  • How To Track Outbound Clicks Using Javascript
  • How to get total seconds elapsed since the beginning of the month?
  • Protractor: Stale element reference at "browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);"
  • Access to an array inside an object
  • Reseting an JavaScript Interval with different value?
  • Learning Angular for the first time - version 2 or 4?
  • Rendering RSS feed (XML) in React with jquery, why do object values parsed from the feed seem empty?
  • Node.js xml2js http.request tag matching
  • applying texture to custom plane geometry in Threejs
  • How do I pass an Event as a function parameter in HTML written inside JavaScript variable?
  • Interface of object parameter with default value and default property
  • Does using try / catch rather than `.catch` observable operator with XHR requests reduce performance?
  • In IE11 background colors not working on printing
  • TypeScript interface signature "(): string"
  • Is synchronous XMLHttpRequest supported in Internet Explorer 10 and 11?
  • Axios function not returning any values with js
  • How to use firestore TIMESTAMP to create time-stamp in JavaScript
  • Instantiate subclass without constructing
  • Outputing a created object in javascript to a server side JSON file
  • Transition the numeric labels in a bar chart
  • createBottomTabNavigator: hide just one tab from the tabBar
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com