Javascript // searching JSON objects quick // accessing JSON elements

OBJECT:

'use strict';

var slotIndexes = [
    { 
	'slot' : 'live',
	'index': 0
    },
    { 
	'slot' : 'achtziger',
	'index': 1
    },
    { 
	'slot' : 'neunziger',
	'index': 2
    },
    { 
	'slot' : 'relax',
	'index': 3
    },
    { 
	'slot' : 'rock',
	'index': 4
    },
    { 
	'slot' : 'brandneu',
	'index': 5
    },
    { 
	'slot' : 'black and dance',
	'index': 6
    },
    { 
	'slot' : 'deutsche hits',
	'index': 7
    },
// RECOUNT INDEXES IN CASE OF ENABLING WEIHNACHTSHITS
//    { 
//	'slot' : 'weihnachtshits',
//	'index': 8
//    },
// RECOUNT INDEXES IN CASE OF ENABLING WEIHNACHTSHITS
    { 
	'slot' : 'berlin club',
	'index': 8
    },
    { 
	'slot' : 'fetenhits',
	'index': 9
    },
    { 
	'slot' : 'news',
	'index': 10
    },
    { 
	'slot' : 'nachrichten',
	'index': 10
    }
];

module.exports = slotIndexes;

SEARCHING:


var slotIndexes  = require('./slotIndexes');
function getIndexBySlot(slot) {
  return slotIndexes.filter(
      function(slotIndexes){ return slotIndexes.slot == slot }
  );
};

 ...
var indexFound = getIndexBySlot(channel);
 ...
if ("undefined" !== typeof indexFound[0]) {
  console.log('DEBUG -> ' + this.handler.state + ' Slot found!');
  this.attributes['index'] = indexFound[0].index;
  this.attributes['offsetInMilliseconds'] = 0;
}


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.