How to iterate an array of objects in Javascript -


i have object (obj) contains content of excel sheet (using node-xlsx library). console.log(obj) gives me following data structure:

[ { name: 'autostar report', data:  [ [object],    [],    [object],    [object],    [object],    [object],    [object],    [object],    [object],    [object],    [object],    [],    [object] ]}] 

each of objects in data contain values this:

[             8,             "enugu - abuja",             "sienna executive ( 1st )",             5,             "9,000",             "45,000",             "5,500",             "39,500"         ],         [             14,             "enugu - lagos",             "sienna executive ( 1st )",             5,             "9,000",             "45,000",             "8,600",             "36,400"         ] 

each of object contained in data contains 8 values. want insert values database table. each of value goes field in table. please how access values in each data object?

note keep saying "object", when obj.data value array of arrays. arrays, access value numerical index.

so, given data structure, , fact have selected javascript, access data so:

// ensure object has "data" attribute if (obj.hasownproperty('data')) {   // data variable convenience   var data = obj.data;   // loop on each row   (i = 0; < data.length; i++) {     // put row variable convenience     var row = data[i];     // since it's array, access each value index     console.log(row[0]);     console.log(row[1]);     console.log(row[2]);     // ... etc ...   } } 

here's working fiddle

when comes processing things this, library such underscore or lodash sure come in handy.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -