Retrieving nested details from info stored in a database - javascript

So I have a list of movies stored with a database and when I make a request to the endpoint the data is returned as such
**{
"Actors": [],
"_id": "613345b5c3e971923de94876",
"Title": "Gladiator",
"Description": "A former Roman General sets out to exact vengeance against the corrupt emperor who murdered his family and sent him into slavery.",
"ImagePath": "https://m.media-amazon.com/images/I/51m50jXZsUL._AC_.jpg",
"Featured": true,
"Genre": [
{
"_id": "61373bf26af4f5693de54a3e",
"Name": "Action",
"Description": "Action films involve one or more heroes thrust into a series of challenges requiring physical feats, extended fights, extensive stunts and frenetic chases.Story and character development are generally secondary to explosions, fist fights, gunplay and car chases. Both historically and currently, action films have wide commercial appeal and enjoy box office success. The action film revolves around a narrative, to be sure, but more importantly than that, a hero; when a moviegoer thinks of an action picture, more often than not they are thinking of a specific actor and the obstacles their character(s) must overcome."
}
],
"Director": [
{
"_id": "613741376af4f5693de54a41",
"Name": "Ridley Scott",
"Bio": "Ridley Scott is an English film producer and director, regarded as one of the biggest names in Hollywood. Ridley is known for his science-fiction horror films, such as the cult classic ‘Alien’ and the science-fiction existential drama ‘Blade Runner.’ Belonging to an army family, Scott was in love with films since childhood. He began his career with short films and eventually made his first feature film, ‘The Duellists,’ in 1977. The film won the ‘Best Debut Film’ honor at the ‘Cannes Film Festival.’ However, it was his second feature film ‘Alien’ that introduced him to Hollywood in a grand style. His highly moody and atmospheric style of directing was fairly new to mainstream Hollywood audiences. Scott quickly sealed his place as one of the most prominent young directors. Scott repeated his mainstream success with ‘Blade Runner.’ Over the years, with the success of films such as ‘Kingdom of Heaven,’ ‘Robin Hood,’ and ‘Black Hawk Down,’ he became a name to reckon with. Of late, he has garnered appreciation for films such as ‘Gladiator,’ ‘The Martian,’ ‘Prometheus,’ and ‘Alien: Covenant.’ He has earned multiple nominations for prestigious awards such as the ‘Emmy Award,’ the ‘Academy Award,’ and the ‘Golden Globe Award.’ He has won two ‘Emmies’ too",
"Birth": "1937",
"Death": ""
}
]
}**
When I try to retrieve this information in another view
**<div className = "movie-director">
<span className = "label">Director: </span>
<span className = "value">{movie.Director.Name}</span>**
All I get is the ID of the director. I have tried to access the array using Array[].name but can't seem to get anything to display. Any suggestions?

Related

How to access object property that has a date format?

I need to access some data from NASA's API, which is in a nested object. Their data is sorted by date, so each key is formatted like so: 2018-09-07
const asteroidList = this.props.asteroids.near_earth_objects //works fine, can access data up to this point
console.log(asteroidList)
const asteroidList = this.props.asteroids.near_earth_objects[2018-09-07] // "Legacy octo literals are not allowed in strict mode" ????
console.log(asteroidList) //errors out
I cannot access anything past this point, because I keep getting an error from my text editor. I'm assuming there must be some kind of conversion method or something to read dates that I don't know about, but I can't find anything for object key-value pairs.
I check what NASA APIs response is, and the key is not a date-value but the "date" string.
So if you have a list of objects and you want to access only the one with a specific date you have to iterate over those objects and search for that particular object:
const list = [
{
"date": "1995-06-16",
"explanation": "Today's Picture: Explanation: If the Earth could somehow be transformed to the ultra-high density of a neutron star , it might appear as it does in the above computer generated figure. Due to the very strong gravitational field, the neutron star distorts light from the background sky greatly. If you look closely, two images of the constellation Orion are visible. The gravity of this particular neutron star is so great that no part of the neutron star is blocked from view - light is pulled around by gravity even from the back of the neutron star. We keep an archive file. Astronomy Picture of the Day is brought to you by Robert Nemiroff and Jerry Bonnell . Original material on this page is copyrighted to Robert Nemiroff and Jerry Bonnell.",
"hdurl": "https://apod.nasa.gov/apod/image/e_lens.gif",
"media_type": "image",
"service_version": "v1",
"title": "Neutron Star Earth",
"url": "https://apod.nasa.gov/apod/image/e_lens.gif"
},
{
"date": "1999-07-11",
"explanation": "Today's Picture: Explanation: If the Earth could somehow be transformed to the ultra-high density of a neutron star , it might appear as it does in the above computer generated figure. Due to the very strong gravitational field, the neutron star distorts light from the background sky greatly. If you look closely, two images of the constellation Orion are visible. The gravity of this particular neutron star is so great that no part of the neutron star is blocked from view - light is pulled around by gravity even from the back of the neutron star. We keep an archive file. Astronomy Picture of the Day is brought to you by Robert Nemiroff and Jerry Bonnell . Original material on this page is copyrighted to Robert Nemiroff and Jerry Bonnell.",
"hdurl": "https://apod.nasa.gov/apod/image/e_lens.gif",
"media_type": "image",
"service_version": "v1",
"title": "Neutron Star Earth",
"url": "https://apod.nasa.gov/apod/image/e_lens.gif"
},
{
"date": "2010-01-22",
"explanation": "Today's Picture: Explanation: If the Earth could somehow be transformed to the ultra-high density of a neutron star , it might appear as it does in the above computer generated figure. Due to the very strong gravitational field, the neutron star distorts light from the background sky greatly. If you look closely, two images of the constellation Orion are visible. The gravity of this particular neutron star is so great that no part of the neutron star is blocked from view - light is pulled around by gravity even from the back of the neutron star. We keep an archive file. Astronomy Picture of the Day is brought to you by Robert Nemiroff and Jerry Bonnell . Original material on this page is copyrighted to Robert Nemiroff and Jerry Bonnell.",
"hdurl": "https://apod.nasa.gov/apod/image/e_lens.gif",
"media_type": "image",
"service_version": "v1",
"title": "Neutron Star Earth",
"url": "https://apod.nasa.gov/apod/image/e_lens.gif"
}
]
list.forEach(element => {
if (element.date === '1999-07-11') {
console.log(element);
}
});
You need to pass 2018-09-07 inside quotes "2018-09-07"
Also add check for undefined cases to avoid error.
const asteroidList = this.props.asteroids && this.props.asteroids.near_earth_objects && this.props.asteroids.near_earth_objects['2018-09-07']
console.log(asteroidList)

How to remove html tags from json data in react native? [duplicate]

This question already has answers here:
How to strip HTML tags from string in JavaScript? [duplicate]
(4 answers)
Closed 5 years ago.
In my React Native app i'm fetching json data which contains raw html tags.How to remove the html tags from that?Following is the json response i'm getting
[{
"data": {
"course": {
"id": 2864,
"name": "2. Understanding India’s economic transition",
"date_created": 1506154480,
"status": "publish",
"price": false,
"price_html": "FREE",
"total_students": 0,
"seats": "",
"start_date": false,
"average_rating": 0,
"rating_count": 0,
"featured_image": "https://www.mywebsite.com/lms/wp-content/themes/wplms/assets/images/avatar.jpg",
"categories": [],
"instructor": {
"id": "22",
"name": "aami",
"avatar": "https://www.mywebsite.com/lms/wp-content/uploads/2017/11/favicon.png",
"sub": ""
},
"menu_order": 0
},
"description": "<p style=\"text-align: justify;\">India is undergoing an economic, social and technological transformation. Perhaps no other phase is going to be as critical as the present one in shaping the future of the country as well as determining the welfare of the people. The economic transition is the vital ingredient of these overall change. Faster growth accompanied by industrial sector expansion, skill addition to the people, creation of quality infrastructure etc. will fuel this growth phase.</p>\n<p style=\"text-align: justify;\">For understanding how important is the present development phase, we have to adopt a historical and comparative study. Following factors helps us to understand the present development phase of India.</p>\n\n<ol style=\"text-align: justify;\">\n \t<li><strong>Achievement of higher growth rate as a middle-income economy. </strong></li>\n</ol>\n<p style=\"text-align: justify;\">India at present is a lower middle-income economy and has to become a high-income economy undergoing a rapid growth phase extending at least three decades.</p>\n<p style=\"text-align: justify;\">Most important narrative about the Indian economy is that it is the third largest in the world in terms of Purchasing Power Parity GDP. But a superior way to asses a country’s development is to consider per capita income. The widely used ranking about countries’ economic position is that of the World Bank’s GDP Per capita (constant US $) and the data for 2016 shows that India’s per capita income is $1861 compared to China’s $ 6994.</p>\n<p style=\"text-align: justify;\">Table: Categorization of countries by World Bank</p>\n\n<table>\n<tbody>\n<tr>\n<td width=\"198\"><strong>Category</strong></td>\n<td width=\"318\"><strong>PCI as on 2015 in constant US Dollar</strong></td>\n</tr>\n<tr>\n<td width=\"198\">Low Income Economy</td>\n<td width=\"318\">$ 1025 or less</td>\n</tr>\n<tr>\n<td width=\"198\">Middle Income Economy\n\n(India - $ 1861)</td>\n<td width=\"318\">$1026 to $4035 (Lower Middle Income)\n\n$4036 to $12475 (Upper Middle Income)</td>\n</tr>\n<tr>\n<td width=\"198\">Higher Income Economy</td>\n<td width=\"318\">$ 12476 and above</td>\n</tr>\n</tbody>\n</table>\n<p style=\"text-align: justify;\">According to World Bank metrics, a country with less than $1045 is considered as low-income economy whereas one with a PCI of $12736 or higher is considered as a higher income economy. Higher income means higher standard of living. India is at the bottom of the lower middle-income economies and has to achieve higher economic growth, structural changes including industrialisation to raise per capita income near to the $12736 mark in the long run. This is what the country has to achieve through the transition.</p>\n\n<ol style=\"text-align: justify;\" start=\"2\">\n \t<li><strong> Industrial sector expansion</strong></li>\n</ol>\n<p style=\"text-align: justify;\">There are several factors that drives the economy to prosperity. Per capita income is just a monitored goal. How it can be raised is through achieving more productivity and employment generation in the sectors that can create big changes is decisive element for the country’s transition. Here comes the role of industrial sector. The industrial sector is known for generating huge employment with minimum skill addition. Similarly, no other sector has higher level of tradability as the industrial sector (means a country can earn big income through exports). Graduating to an expanded services sector without undergoing industrialisation will be self-defeating and unsuitable to a big economy like India. Depending on services sector for exports will not reward as other countries like to protect their services sector from the inflow of India’s skilled persons. If India can increase the contribution of the industrial sector in GDP from the present 30 per cent to say 40-45%, it implies that sizable income and employment are created in the sector.</p>\n\n<ol style=\"text-align: justify;\" start=\"3\">\n \t<li><strong> Skilling the people when demography favours.</strong></li>\n</ol>\n<p style=\"text-align: justify;\">India has the largest number of young people in the world besides having largest workforce age group population. This situation is expected to remain till 2045. Now, youth means higher ability to produce, consume and thus stimulate overall economic activities. As in the case of an individual, better things happen for an economy when it is young.</p>\n\n<ol style=\"text-align: justify;\" start=\"4\">\n \t<li><strong> Infrastructure generation.</strong></li>\n</ol>\n<p style=\"text-align: justify;\">Infrastructure is the platform for fueling growth. The government has launched several programmes to build quality infrastructure to assist economic transformation. In the industrial sector, there is the industrial corridor project; in transportation – there is the NHDP, PMGSY, Bhartamala, Sagarmala etc. Similarly, digital infrastructure is undergoing a qualitative improvement along with the education sector.</p>\n\n<ol style=\"text-align: justify;\" start=\"5\">\n \t<li><strong> Building invention and Innovation.</strong></li>\n</ol>\n<p style=\"text-align: justify;\">Development is dynamic and present day developing economies can’t achieve development with the strategy of the past. Fourth industrialisation, robotics, artificial intelligence etc., proved that industrialisation is not labour oriented. Here, Countries like China with the aid of superior technology with its sizable labour force can produce and supply goods to the entire world. Competing in the new age industrial sector need good technological adaptation and a progressive national invention and educational systems.</p>\n\n<ol style=\"text-align: justify;\" start=\"6\">\n \t<li><strong> Easing of Doing Business.</strong></li>\n</ol>\n<p style=\"text-align: justify;\">India’s business environment is historically suffocated by excess regulations and slow bureaucratic functions that are unsuitable for enterprise development.. But in recent years, institutional reforms are taking place and development blocking regulations are in the process of elimination.</p>\n<p style=\"text-align: justify;\">Development has become a major theme of the government and every issue related with economic prosperity are sophisticatedly addressed. Improvements in all the above field is slowly yielding results. Despite the adverse global slowdown and anti-globalisation headwinds, India continues to be the fastest growing large economy.</p>",
"curriculum": false,
"reviews": [],
"instructors": [{
"id": "22",
"name": "tojo",
"avatar": "https://www.mywebsite.com/lms/wp-content/uploads/2017/11/favicon.png",
"sub": "",
"average_rating": 0,
"student_count": 0,
"course_count": "0",
"bio": false
}],
"purchase_link": false
},
"headers": [],
"status": 200
}]
I'm listing description inside a card. So how to remove html tags?Please do help..Is there a way to do this?
What about this?
const regex = /(<([^>]+)>)/ig;
const result = data.description.replace(regex, '');
I also faced this challenge in my app.
After trying several library, i'd like to recommand you react-native-render-html
It allows you to provide 'html' to a Native component and have a simple text as an output.
You can also customize each tag to give them specific style or ignore some of them.
It does not require you to use 'react link' to make it work so you can use it in your expo app as well.
Hope it helps.

AngularJS + Json: How to render html

(I know this question was asked many times, but I believe my setup is different and so a new question needed to be asked with a different scenario)
There are plenty of examples out there that shows how to Render HTML, but I can't seem to get this to work with any of the examples. I'd like to render html the {{aboutlongs[0].description}} (this has <br /> tags that I would like to render as html)
Here's the js:
App.controller('aboutLongCtrl', function ($scope, $http) {
$http.get('test_data/ar_org.json')
.then(function (res) {
$scope.aboutlongs = res.data.aboutlong;
});
});
the HTML:
<div class="background-white p20 reasons" ng-controller="aboutLongCtrl" >
<h6><b>About {{aboutlongs[0].name}}</b></h6>
<div class="reason-content" >
{{aboutlongs[0].description}}
</div>
</div>
Can anyone point me to the right direction?
The Json file:
"aboutlong": [{
"name": "Women's March",
"description": "The rhetoric of the past election cycle has insulted, demonized, and threatened many of us - immigrants of all statuses, Muslims and those of diverse religious faiths, people who identify as LGBTQIA, Native people, Black and Brown people, people with disabilities, survivors of sexual assault - and our communities are hurting and scared. We are confronted with the question of how to move forward in the face of national and international concern and fear.<br /><br />In the spirit of democracy and honoring the champions of human rights, dignity, and justice who have come before us, we join in diversity to show our presence in numbers too great to ignore. The Women's March on Washington will send a bold message to our new government on their first day in office, and to the world that women's rights are human rights. We stand together, recognizing that defending the most marginalized among us is defending all of us.<br /><br />We support the advocacy and resistance movements that reflect our multiple and intersecting identities. We call on all defenders of human rights to join us. This march is the first step towards unifying our communities, grounded in new relationships, to create change from the grassroots level up. We will not rest until women have parity and equity at all levels of leadership in society. We work peacefully while recognizing there is no true peace without justice and equity for all.<br /><br />Women's rights are human rights, regardless of a woman's race, ethnicity, religion, immigration status, sexual identity, gender expression, economic status, age or disability. We practice empathy with the intent to learn about the intersecting identities of each other. We will suspend our first judgement and do our best to lead without ego."
}]
Posts I've tried:
How to render a HTML tag from json value using angularJs
Angular.js How to render a HTML tag from json file
AngularJS : Insert HTML into view
if you want to render string to html i recommand to use $sce.trustAsHtml(html).
you can create a sample filter like this
.filter('trustHtml',function($sce){
return function(html){
return $sce.trustAsHtml(html)
}
})
call the filter like this inside ng-bind-html
<div class="reason-content" ng-bind-html="aboutlongs[0].description | trustHtml" ></div>
Demo
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.aboutlongs = [{
"name": "Women's March",
"description": "The rhetoric of the past election cycle has insulted, demonized, and threatened many of us - immigrants of all statuses, Muslims and those of diverse religious faiths, people who identify as LGBTQIA, Native people, Black and Brown people, people with disabilities, survivors of sexual assault - and our communities are hurting and scared. We are confronted with the question of how to move forward in the face of national and international concern and fear.<br /><br />In the spirit of democracy and honoring the champions of human rights, dignity, and justice who have come before us, we join in diversity to show our presence in numbers too great to ignore. The Women's March on Washington will send a bold message to our new government on their first day in office, and to the world that women's rights are human rights. We stand together, recognizing that defending the most marginalized among us is defending all of us.<br /><br />We support the advocacy and resistance movements that reflect our multiple and intersecting identities. We call on all defenders of human rights to join us. This march is the first step towards unifying our communities, grounded in new relationships, to create change from the grassroots level up. We will not rest until women have parity and equity at all levels of leadership in society. We work peacefully while recognizing there is no true peace without justice and equity for all.<br /><br />Women's rights are human rights, regardless of a woman's race, ethnicity, religion, immigration status, sexual identity, gender expression, economic status, age or disability. We practice empathy with the intent to learn about the intersecting identities of each other. We will suspend our first judgement and do our best to lead without ego."
}]
})
.filter('trustHtml',function($sce){
return function(html){
return $sce.trustAsHtml(html)
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div class="background-white p20 reasons" >
<h6><b>About {{aboutlongs[0].name}}</b></h6>
<div class="reason-content" ng-bind-html="aboutlongs[0].description | trustHtml" >
</div>
</div>
</div>
Have a look at this awesome article Angular Trust Filter
angular.module('myApp', [])
.controller('aboutLongCtrl', ['$scope', '$sce', function($scope, $sce) {
$scope.aboutlongs = [{
"name": "Women's March",
"description": $sce.trustAsHtml("The rhetoric of the past election cycle has insulted, demonized, and threatened many of us - immigrants of all statuses, Muslims and those of diverse religious faiths, people who identify as LGBTQIA, Native people, Black and Brown people, people with disabilities, survivors of sexual assault - and our communities are hurting and scared. We are confronted with the question of how to move forward in the face of national and international concern and fear.<br /><br />In the spirit of democracy and honoring the champions of human rights, dignity, and justice who have come before us, we join in diversity to show our presence in numbers too great to ignore. The Women's March on Washington will send a bold message to our new government on their first day in office, and to the world that women's rights are human rights. We stand together, recognizing that defending the most marginalized among us is defending all of us.<br /><br />We support the advocacy and resistance movements that reflect our multiple and intersecting identities. We call on all defenders of human rights to join us. This march is the first step towards unifying our communities, grounded in new relationships, to create change from the grassroots level up. We will not rest until women have parity and equity at all levels of leadership in society. We work peacefully while recognizing there is no true peace without justice and equity for all.<br /><br />Women's rights are human rights, regardless of a woman's race, ethnicity, religion, immigration status, sexual identity, gender expression, economic status, age or disability. We practice empathy with the intent to learn about the intersecting identities of each other. We will suspend our first judgement and do our best to lead without ego.")
}];
}])
;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" class="background-white p20 reasons" ng-controller="aboutLongCtrl" >
<h6><b>About {{aboutlongs[0].name}}</b></h6>
<div class="reason-content" ng-bind-html="aboutlongs[0].description">
</div>
</div>

Retrieving Extract from Wikipedia API [duplicate]

This question already has answers here:
Accessing an object property with a dynamically-computed name
(19 answers)
Closed 6 years ago.
So I get a JSON response which looks like this:
{
"batchcomplete": "",
"query": {
"pages": {
"97646": {
"pageid": 97646,
"ns": 0,
"title": "Die Hard",
"extract": "Die Hard is a 1988 American action film directed by John McTiernan and written by Steven E. de Souza and Jeb Stuart. It follows off-duty New York City Police Department officer John McClane (Bruce Willis) as he takes on a group of highly organized criminals led by Hans Gruber (Alan Rickman), who perform a heist in a Los Angeles skyscraper under the guise of a terrorist attack using hostages, including McClane's wife Holly (Bonnie Bedelia), to keep the police at bay.\nIt is based on Roderick Thorp's 1979 novel Nothing Lasts Forever, the sequel to 1966's The Detective, which was adapted into a 1968 film of the same name that starred Frank Sinatra. Fox was therefore contractually obligated to offer Sinatra the lead role in Die Hard, but he turned it down. The studio then pitched the film to Arnold Schwarzenegger as a sequel to his 1985 action film Commando; he turned it down, as well, and the studio finally and reluctantly gave it to Willis, then known primarily as a comedic television actor.\nMade for $28 million, Die Hard grossed over $140 million theatrically worldwide, and was given a positive reception from critics. The film turned Willis into an action star, became a metonym for an action film in which a lone hero fights overwhelming odds, and has been named one of the best action movies ever made. The film also ranks #29 on Empire magazine's 2008 list of the 500 greatest movies of all time. The film's success spawned the Die Hard franchise, which includes four sequels (Die Hard 2, Die Hard with a Vengeance, Live Free or Die Hard and A Good Day to Die Hard), video games, and a comic book."
}
}
}
}
Here is the link: https://en.wikipedia.org/w/api.php?format=jsonfm&action=query&prop=extracts&exintro=&explaintext=&titles=Die%20Hard
And I want to just get the extract of the page. The trouble is I don't know the pageid until I get the response, and so cannot call the extract.
To get the extract for this example I would have to do:
var data = JSON.parse(this.response);
console.log(suggestionData.query.pages.97646.extract);
So I have tried to get the value of the page id by making it a variable to add into the query like this:
var data = JSON.parse(this.response);
var pageid = [suggestionData.query.pages[0];
console.log(suggestionData.query.pages. + pageid +.extract);
But this hasn't been successeful as the variable pageid comes up as:
"97646": {
"pageid": 97646,
"ns": 0,
"title": "Die Hard",
"extract": "Die Hard is a 1988 American action film directed by John McTiernan and written by Steven E. de Souza and Jeb Stuart. It follows off-duty New York City Police Department officer John McClane (Bruce Willis) as he takes on a group of highly organized criminals led by Hans Gruber (Alan Rickman), who perform a heist in a Los Angeles skyscraper under the guise of a terrorist attack using hostages, including McClane's wife Holly (Bonnie Bedelia), to keep the police at bay.\nIt is based on Roderick Thorp's 1979 novel Nothing Lasts Forever, the sequel to 1966's The Detective, which was adapted into a 1968 film of the same name that starred Frank Sinatra. Fox was therefore contractually obligated to offer Sinatra the lead role in Die Hard, but he turned it down. The studio then pitched the film to Arnold Schwarzenegger as a sequel to his 1985 action film Commando; he turned it down, as well, and the studio finally and reluctantly gave it to Willis, then known primarily as a comedic television actor.\nMade for $28 million, Die Hard grossed over $140 million theatrically worldwide, and was given a positive reception from critics. The film turned Willis into an action star, became a metonym for an action film in which a lone hero fights overwhelming odds, and has been named one of the best action movies ever made. The film also ranks #29 on Empire magazine's 2008 list of the 500 greatest movies of all time. The film's success spawned the Die Hard franchise, which includes four sequels (Die Hard 2, Die Hard with a Vengeance, Live Free or Die Hard and A Good Day to Die Hard), video games, and a comic book."
}
I also want to use javascript and not jQuery etc.
Try this fiddle : https://jsfiddle.net/u9dnm70b/
var response = '{"batchcomplete": "","query": {"pages": {"97646": {"extract": "abcd" }}}}';
var suggestionData = JSON.parse(response);
var pageid = Object.keys(suggestionData.query.pages)[0];
console.log(suggestionData.query.pages[pageid].extract);
You can use Object.keys(jsonObj); to find out keys.
In your case var pageid is a json object. To access value, take a look at this thread (get keys of json-object in JavaScript)
In short answer is
for key in pageid
content= pageid[key]
extract = content.extract
You can extract pageid like this:
var pageid = Object.keys(suggestionData.query.pages)[0];
Then this should work:
console.log(suggestionData.query.pages[pageid].extract");

Javascript find a string in a multidimensional array and return that array?

I have an array like
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'},
];
and I have a movie listing, and I want to see if the current movie listings mId is equal to any other mId's in the array schedule, if so return them in an array so I can loop through them and display the other results.
I am a bit confused with how to do this? I assumed you use array.filter but I can't seem to figure it out.
Any help?
array.filter should work. Try the following code:
var filtered = schedule.filter(function(val) {
return val['mId'] != searchMid;
});
where searchMid is the mid you are searching for.

Categories