I have the following data. I would like to be able to efficiently filter out all of the objects in the sites
array that do not have a matching segmentCode
in array of segmentCodes
. I can use dojo or native javascript, but I do not have access to any other libraries.
var segmentCodes = ["10", "20","30","40"];
var sites = [
{"siteid":1, "segmentCode":"10"},
{"siteid":2, "segmentCode":"10"},
{"siteid":3, "segmentCode":"20"},
{"siteid":4, "segmentCode":"30"},
{"siteid":5, "segmentCode":"70"},
{"siteid":6, "segmentCode":"999"}];
The result should look like this:
[{"siteid":5, "segmentCode":"70"}, {"siteid":6, "segmentCode":"999"}]
Thanks in advance.