Skip to content

Instantly share code, notes, and snippets.

@adaam2
Created July 2, 2014 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adaam2/44363f470d638e3dba23 to your computer and use it in GitHub Desktop.
Save adaam2/44363f470d638e3dba23 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</body>
</html>
var json = [
{
"type": "LOCATION",
"name": "St."
},
{
"type":"O"
},
{
"type": "LOCATION",
"name": "Albans"
},
{
"type":"O"
},
{
"type": "PERSON",
"name": "Adam"
},
{
"type":"O"
},
{
"type": "PERSON",
"name": "Bull"
},
{
"type":"THING",
"name":"Neymar"
},
{
"type":"O"
},
{
"type":"NOTATHING",
"name":"Benzema"
}
], background = "O";
$(function(){
var prevType = "";
var prevValue = "";
$.each(json,function(i){
var type = json[i].type;
if(type != "O") {
var name = json[i].name;
if(type === prevType) {
var combined = prevValue + ' ' + name;
console.log(combined);
}
prevType = type;
prevValue = name;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment