Filtering JSON data

后端 未结 8 549
暖寄归人
暖寄归人 2020-12-24 08:59

I have a JSON file which contains data like the following:

{\"posts\": [ 
    { \"title\":\"1\", \"url\":\"n1.png\" }, 
    { \"title\":\"2\", \"url\":\"n2.p         


        
8条回答
  •  自闭症患者
    2020-12-24 09:20

    try this

    var q = new RegExp(req.query.q,'i');
    
    posts = posts.filter(function(item){
        if(item.title.match(q) || item.url.match(q)){
            return item;
        }
    });
    

提交回复
热议问题