javascript - Is it possible to create an object with different values determined by the id of the object? -


so have information fra .csv file want present in web page. far have var lines long string of information each column in csv file separated ;. loops elements want:

           `for (var = lines.length - 1; >= 0; i--) {                 var row = lines[i];                                  var header = lines[i].tostring().split(":");                                     var elements = header[1].tostring().split(";");                               (var j =0; j <= elements.length - 1; j++) {                     console.log(elements[j]);                 };                            };`   

when print console each column:

id: 2 description: loung paa selskapssiden with: spiller where: samfundet - selskapssiden date: 06.02.2014 time: 23.00  

which want. now, want add information object or whatever. how do that? possible add object can information doing object call like:

information.id.description 

where for loop on .id? or there easier way storing , getting information? perhaps jquery?

use id key in object, this

var information = {};  (var = lines.length - 1; >= 0; i--) {     var row = lines[i];                      var header = lines[i].tostring().split(":");                         var elements = header[1].tostring().split(";");                    (var j =0; j <= elements.length - 1; j++) {          information[elements[j].id] = elements[j];     } }; 

then can later with

information[2].description //          ^^ id property 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -