How can I add omitable dynamic values to an array in Javascript? -


i adding dynamical values array 2 tables (datatables.js) in here:

var formarray = {     "valuefroma0" : table1.row(0).data()[1],     "valuefroma1" : table1.row(1).data()[1],     "valuefromb0" : table2.row(0).data()[1],     "valuefromb1" : table2.row(1).data()[1] }; 

these tables dynamically created. of values (or of them) can empty. want omit 'undefined'/empty values during creation array. example, valuefroma1, valuefromb0 , valuefromb1 undefined means there should 1 value in array this:

"valuefroma0" : "5"

try this:

var formarray = {     "valuefroma0" : "7",     "valuefroma1" : undefined,     "valuefromb0" : "5",     "valuefromb1" : undefined };  function removeemptyentries(obj) {     for(var prop in obj)     {         if(obj.hasownproperty(prop) && !obj[prop])             delete obj[prop];     } }   removeemptyentries(formarray); console.log(formarray); 

jsfiddle.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -