Last active
May 10, 2017 21:17
-
-
Save monkeycycle/25949ef867921e12795a5d16d594313d to your computer and use it in GitHub Desktop.
names matching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var arrayOne = [{ | |
"name": "Keny" | |
}, | |
{ | |
"name": "Sloane" | |
}, | |
{ | |
"name": "Elianna" | |
}]; | |
var arrayTwo = [{ | |
"name": "Kenley" | |
}, | |
{ | |
"name": "Sloane" | |
}, | |
{ | |
"name": "Elianna" | |
}]; | |
var newArray = []; | |
console.log("dogname: %o", arrayOne); | |
console.log("peoplename: %o", arrayTwo); | |
//loop through dog names | |
for (var i = 0; i < arrayOne.length; i++) { | |
console.log("dogname: %o", arrayOne[i]); | |
// for each dog name, loop through human name | |
for (var j = 0; j < arrayTwo.length; j++) { | |
// if dog name equals a human name, add to new array | |
if (arrayOne[i].name === arrayTwo[j].name) { | |
console.log("Match: " + arrayOne[i].name + ' ' + arrayTwo[j].name); | |
newArray.push(arrayOne[i].name); | |
} | |
} | |
} | |
console.log(newArray); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment