Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript在多维数组中查找字符串并返回该数组?_Javascript - Fatal编程技术网

Javascript在多维数组中查找字符串并返回该数组?

Javascript在多维数组中查找字符串并返回该数组?,javascript,Javascript,我有一个类似的数组 var schedule = [ {date:'9/21/2011',mId:1,title:'Faith, Fraud and Minimum Wage',director:'George Mihalka',startTime:'9:20 PM',length:'91',genre:'Drama',movieType:'Faith, Fraud and Minimum Wage',trailer:'iVs5VL2kH8s',synopsis:'Halifax act

我有一个类似的数组

    var schedule = [
{date:'9/21/2011',mId:1,title:'Faith, Fraud and Minimum Wage',director:'George Mihalka',startTime:'9:20 PM',length:'91',genre:'Drama',movieType:'Faith, Fraud and Minimum Wage',trailer:'iVs5VL2kH8s',synopsis:'Halifax actor, dramatist and screenwriter Josh MacDonald’s hit play <i>Halo</i> has finally hit the big screen, courtesy of <i>My Bloody Valentine</i> director George Mihalka and legendary producer Colin Neale.\nA tragicomic tale of faith in a skeptical age, <i>Faith, Fraud and Minimum Wage</i> is based on real-life incidents in Nova Scotia that generated international headlines. In the economically depressed town of Nately, a young atheist maverick named Casey discovers the image of Jesus on the outside wall of her coffee-shop workplace. As outside interest builds and Nately finally makes it on the map, Casey’s own strained domestic situation boils to a climax.\nClever, moving and surprisingly respectful, <i>Faith, Fraud and Minimum Wage</i> features sparkling performances from the likes of Picnicface’s Andrew Bush (as the town priest), Callum Keith Rennie (as the dad) and Martha MacIsaac in the central role of Casey.',location:'Parklane',movieTime:'Fri, Sep 3, 7PM',moviePic:'../movies/faithfraudminimumwage/1.png'},
{date:'9/21/2011',mId:2,title:'Mind The Gap',director:'Aaron Au',startTime:'7:00 PM',length:'7',genre:'Drama',movieType:'CBC Atlantic Shorts Gala',trailer:'hbLgszfXTAY',synopsis:'Halifax actor, dramatist and screenwriter Josh MacDonald’s hit play <i>Halo</i> has finally hit the big screen, courtesy of <i>My Bloody Valentine</i> director George Mihalka and legendary producer Colin Neale.\nA tragicomic tale of faith in a skeptical age, <i>Faith, Fraud and Minimum Wage</i> is based on real-life incidents in Nova Scotia that generated international headlines. In the economically depressed town of Nately, a young atheist maverick named Casey discovers the image of Jesus on the outside wall of her coffee-shop workplace. As outside interest builds and Nately finally makes it on the map, Casey’s own strained domestic situation boils to a climax.\nClever, moving and surprisingly respectful, <i>Faith, Fraud and Minimum Wage</i> features sparkling performances from the likes of Picnicface’s Andrew Bush (as the town priest), Callum Keith Rennie (as the dad) and Martha MacIsaac in the central role of Casey.',location:'Oxford Theatre',movieTime:'Fri, Sep 8, 7PM',moviePic:'../movies/faithfraudminimumwage/1.png'},
{date:'9/24/2011',mId:2,title:'Mind The Gap',director:'Aaron Au',startTime:'7:00 PM',length:'7',genre:'Drama',movieType:'CBC Atlantic Shorts Gala',trailer:'hbLgszfXTAY',synopsis:'Halifax actor, dramatist and screenwriter Josh MacDonald’s hit play <i>Halo</i> has finally hit the big screen, courtesy of <i>My Bloody Valentine</i> director George Mihalka and legendary producer Colin Neale.\nA tragicomic tale of faith in a skeptical age, <i>Faith, Fraud and Minimum Wage</i> is based on real-life incidents in Nova Scotia that generated international headlines. In the economically depressed town of Nately, a young atheist maverick named Casey discovers the image of Jesus on the outside wall of her coffee-shop workplace. As outside interest builds and Nately finally makes it on the map, Casey’s own strained domestic situation boils to a climax.\nClever, moving and surprisingly respectful, <i>Faith, Fraud and Minimum Wage</i> features sparkling performances from the likes of Picnicface’s Andrew Bush (as the town priest), Callum Keith Rennie (as the dad) and Martha MacIsaac in the central role of Casey.',location:'Parklane',movieTime:'Fri, Sep 12, 7PM',moviePic:'../movies/faithfraudminimumwage/1.png'},

];
我有一个电影列表,我想看看当前的电影列表mId是否等于数组计划中的任何其他mId,如果是的话,以数组的形式返回它们,这样我就可以遍历它们并显示其他结果

我有点不明白怎么做?我假设您使用array.filter,但我似乎无法理解


有什么帮助吗?

array.filter应该可以工作。请尝试以下代码:

var filtered = schedule.filter(function(val) {
  return val['mId'] != searchMid;
});

其中searchMid是您要搜索的mid。

我要搜索的值应该放在哪里?假设我正在数组中搜索mId 2。应该是2吗!=瓦尔;还是?哎呀,我的错。忘了包括那个。我去编辑我的答案。