Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

filter data nodejs


app.get('/contactx', (req, res) => {
    console.log('axaac');
    const {search, limit} =req.query
    let sortedProducts = [...products]

    if(search){
        sortedProducts = sortedProducts.filter((product)=>{
            return product.name.startsWith(search)
        })
    }
    if(limit){
        sortedProducts = sortedProducts.slice(0, Number(limit))
        }
        if(sortedProducts.length<0){
            return res.status(402).json({success: true},{data:[]})
        }

        return res.status(402).json(sortedProducts)
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: assign-only-if-property-exists-in-target-object 
Javascript :: jquery call service 
Javascript :: sinalR 
Javascript :: nextjs app wdyr 
Javascript :: Alternative Bind() Syntax For JavaScript 
Javascript :: react text editor snippet 
Javascript :: using parseint in javascript 
Javascript :: Printer Errors 
Javascript :: how to set socket io into global express 
Javascript :: ... Notation In JavaScript 
Javascript :: phaser reverse matrix rows 
Javascript :: how to have two entry files in webpack 
Javascript :: react native text input allow only numbers 
Javascript :: node-schedule cancel job 
Javascript :: javascript ls 
Javascript :: querySelectorAll select multiple element types 
Javascript :: Object.entries() For A JSON 
Javascript :: save to text or html file very good 
Javascript :: useDapp connect metamask example 
Javascript :: react users list modal 
Javascript :: Control a progress bar for custom video player 
Javascript :: button style when clicked and unclicked react material 
Javascript :: Backbone Error: Uncaught TypeError: this.set is not a function 
Javascript :: How many options are there to climb a ladder with N 
Javascript :: react native long form keyboard awaire 
Javascript :: copy array 
Javascript :: javascript filter array of object by id 
Javascript :: moment max 
Javascript :: traversing in jquery 
Javascript :: animation js 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =