Skip to content

Instantly share code, notes, and snippets.

@princejoseph
Last active June 26, 2018 17:12
Show Gist options
  • Save princejoseph/35c7b31be34e2ea84f7082b15468c2f9 to your computer and use it in GitHub Desktop.
Save princejoseph/35c7b31be34e2ea84f7082b15468c2f9 to your computer and use it in GitHub Desktop.
Search
let searchTerm = "YGR556LRKB0"
let result = {"data":{"modelSearch":{"totalCount":5,"models":[{"id":"01207501198YGR556LRKB0","number":"YGR556LRKB0","title":"REFRIGERATOR RANGE","brand":{"name":"WHIRLPOOL"},"vocabularies":[{"name":"Applicances"},{"name":"Cooking*"},{"name":"Gas Ranges/Ovens*^"}],"partCount":null},{"id":"01648001198YGR556LRKP0","number":"YGR556LRKP0","title":"REFRIGERATOR","brand":{"name":"WHIRLPOOL"},"vocabularies":[{"name":"Appliances"},{"name":"Refrigerators*^"},{"name":"Refrigerator Accessories^"}],"partCount":109},{"id":"120000012329030","number":"9030","title":"SEWING MACHINE","brand":{"name":"SINGER"},"vocabularies":[{"name":"Sewing*"},{"name":"Sewing*"}],"partCount":423},{"id":"01650001198GD5RHAXSQ01","number":"GD5RHAXSQ01","title":"SIDE-BY-SIDE REFRIGERATOR","brand":{"name":"WHIRLPOOL"},"vocabularies":[{"name":"Appliances"},{"name":"Refrigerators*^"},{"name":"Side-by-Side Refrigerator^"}],"partCount":109},{"id":"0165000058225357398600","number":"25357398600","title":"REFRIGERATOR","brand":{"name":"Kenmore"},"vocabularies":[{"name":"Appliances"},{"name":"Refrigerators*^"},{"name":"Side-by-Side Refrigerator^"}],"partCount":109}]}}}
let models = result.data.modelSearch.models
// let model = models.find(function(model) {
// return model.id === searchTerm
// })
let model = models.find(model => model.number === searchTerm)
if(model) {
// do something
alert(true)
} else {
// do something
alert(false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment