@parth.patel,
FAQ:
#1: I want to make a library function which takes the index as a parameter and traverses that row through all the columns of a table (not a specific table, it should work with any table⦠hence the column names are unknown) and returns the column names with the string ā/imagesā in them
// ?? instructions unclear, this is doable but requires intracate knowledge of loops
function getColumns(table, callback) {
readRecords(table, [], function (v) {
var columns = {};
for (var c in v[0]) {
columns[c] = [];
}
for (var i = 0; i < v.length; i++) {
for (var n in v[i]) {
columns[n].push(v[i][n]);
}
}
callback(columns);
})
}
// use case in where all columns are formatted in a general array
getColumns("Your Table", function (col) {
console.log(col);
})
#2: Also, we know how to traverse vertically (ie loop through a range of indices) but how to we traverse horizontally (through a range of columns)?
This has been answered previous by the demo function given up top, to move vertically youāll need the whole dataset by using, readRecords, this will provide all necessary data from the given table with a small hit to performance⦠which i doubt you care about
#3: Another question that is related - I know of just one way in App Lab to access data: using getColumn(tablename, columnname). Is there any other way?
Well yes⦠this was the question proposed based on question #2 was it not? you can find this in the documentation that code.org gives in their documentation since it is one of their listed blocks, you should have no trouble finding it
#4: How about automating this inside a loop that would get the names of columns and store them into numbered variables (thinking of something like:
// DEMO PESUDO CODE PROPOSED BY #4
for (var i=0; i<n, i++){
var ācolā+i = getcolumn(tablename, column i);
}
where n is the number of columns in a table)?
OR is there a way to save the table object inside a variable? like:
var myTable = getTable(āUS States and Territoriesā);
So⦠Iām going to go out on a limb here and say all your problems will most likely be solved by readRecords since this was asked the same time on #2,3,4 along with 1 asking for a scalable function
But to answer your question no, you wanted dynamic column support to be read by any table, what if my naming scheme doesnāt include an iterable number⦠your program breaks and it wonāt support what i want to use which i assume was most likely the conundrum you were having and probably couldnāt explain the exact behaviour you were looking for, most times itās just best to try and dumb it down a bit which is something Iāve been trying to improve upon myself recently
Also My apologies for any typos, syntax errors, or grammar mistakes since this was written in notepad and I donāt exactly feel like fixing anything at the moment, anywho hope this helps!