Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

generic product filter javascript

const compare = r => l => (typeof l === "object" ? contains(r)(l) : l === r);
const contains = r => l =>
  Object.keys(r).every(k => l.hasOwnProperty(k) && compare(r[k])(l[k]));

var list = [
  {
    name: "Alice",
    address: {
      zip: "10000"
    }
  },
  {
    name: "Bob",
    address: {
      zip: "20000"
    }
  },
  {
    name: "Charlie",
    address: {
      zip: "30000"
    }
  }
];

var filter = {
  address: { zip: "10000" }
};

console.log(list.filter(contains(filter)));
// [{"name":"Alice","address":{"zip":"10000"}}]
Comment

generic product filter javascript

filterList(): void {
    let searchtext = this.state.currentSearchBoxValue;
    let searchProperties = this.state.searchBoxOptions.searchProperties;

    let list = this.props.list;

    if(searchtext != undefined && searchtext != '' && searchtext != null) 
    {    
        /* Call filter to filter items that match search criteria */
        const filteredList = list.filter(item => {

            /* Search for any property where the some() criteria is true for 
               current item */
            return searchProperties.some(searchProperty => {

                /* If item value on current searchProperty key includes searchText, 
                   return true. This means some() will return true, and
                   the "item" will be included in filteredList */
                const itemPropertyValue = item[ searchProperty ];

                return itemPropertyValue.includes(searchtext);
            });
        });

        /* Filtered result */
        console.log(filteredList);
    }     
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: add value get value 
Javascript :: visable in viewport 
Javascript :: send offer webrtc 
Javascript :: Getting Specific Element Properties 
Javascript :: cookie parser object null prototype 
Javascript :: intro.js free alternative 
Javascript :: regex generator 
Javascript :: javascrpt 
Javascript :: javascript while function is not defined wait 
Javascript :: how to pass jsp variable as parameter via onclick function in html 
Javascript :: convert an array to other array 
Javascript :: change candle color react highcharts 
Javascript :: JS check the type stored in the name variable in JS 
Javascript :: browserlist nextjs 
Javascript :: how to add carsoul to react project 
Javascript :: react Alert when rate changes 
Javascript :: find regx for password authentication 
Javascript :: xmlhttprequest set route params 
Javascript :: moment js days ago 
Javascript :: how to get file tree of specific folder in node js 
Javascript :: gsheet business days 
Javascript :: likedislike mangodb 
Javascript :: javascript to jquery converter tool 
Javascript :: animating in activityindicator 
Javascript :: how to make messaging website with firebase javascript 
Javascript :: angular 2 on data bound event equivalent 
Javascript :: check if string is json parsable 
Javascript :: logvalue returned from array 
Javascript :: enzym.debug 
Javascript :: nested ternaries react 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =