Built with blockbuilder.org
forked from scresawn's block: objects and arrays
forked from rubin2ma's block: objects and arrays
forked from jorgencm's block: objects and arrays
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
// modify array1 so that each object it contains includes the 2 letter state "id"
array1 = [
{name: "Arizona", location: "Southwest"},
{name: "Virginia", location: "East"},
{name: "Florida", location: "Southeast"}
];
array2 = [
{name: "Virginia", id: "VA"},
{name: "Arizona", id: "AZ"},
{name: "Florida", id: "FL"}
];
array1.forEach(function(a1) {
array2.forEach(function(a2) {
if (a1.name == a2.name) {
a2.id = a1.id;
}
})
})
// print all items that are in both array3
// and array4 to the console.
array3 = ['a','b','c','d'];
array4 = ['a','c','e','f','g'];
</script>
</body>
https://d3js.org/d3.v4.min.js