OBSOLETE node javascript debugging

Mar 5, 07:23 AM

to load underscore (or any cdn) into javascript:

var cdn = ‘https://code.jquery.com/jquery-3.2.1.min.js’ ;
var cdn = “https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js” ;
var cdn=‘https://cdnjs.cloudflare.com/ajax/libs/deepstream.io-client-js/2.1.2/deepstream.js’ ;

var jq = document.createElement(‘script’); jq.src=cdn;
document.getElementsByTagName(‘head’)0.appendChild(jq);

awesome way to use underscore to look up value in an object:

// _master is the object, sequelizeId is the index
console.log( _.findIndex(_master, (_tmpRow)=> { return _tmpRow.sequelizeId === ‘123456’ }) );

// 2017-09-26:
// https://stackoverflow.com/questions/37933445/underscore-js-find-object-which-contains-value-in-array

var master = [ { ‘name’ : ‘listOne’ , data : [ ‘nameOne’,‘nameTwo’] } , { name: ‘listTwo’, ‘data’ : [ ‘nameThree’, ‘nameFour’ ] } ]

function findMe(myObj, myKey) { var retVal=null; _.each(myObj, (val)=> { var byeBye = _.indexOf(val.data, myKey ); if ( _.indexOf(val.data, myKey ) > -1 ) { retVal=val.name; } }) return retVal;
}

console.log( ‘RESULT: ‘ + findMe(master, ‘nameTwo’) )

Mark Edwards

,

---

Commenting is closed for this article.

---