There’s nothing wrong with that code assuming all of the variables in question are arrays.
But TBH, I’ve lost the thread of what’s going on a little and find things like:
strikeArr.push(rowList[j].c[0].v);
hard to parse and prone to errors.
If I was you, I’d go back through your code and log the values of each variable (one by one) until you can localize where the mistake is.
I can help you sort your problem out, but I have no idea what many of the variables, like openinterestdocs, hold.
What would be better is if you can hardcode them (for the purpose of troubleshooting) and post a code snippet here with which I can recreate your problem.
console.log("Here # 1"); // This prints
console.log("value of i=" + i); // This prints
console.log("value of strikeArr=" + strikeArr); // This prints
masterArry[i].push(strikeArr); // what is the trouble here ?
console.log("Here # 2"); // This DOES NOT print
My advice would be to strip away the irrelevant pieces until you get down to the root of your problem. You will either solve the issue yourself, or end up with some minimal code that recreates your issue that you can post here.
please see these prints. does these prints look alright ?
console.log("Here # 1"); // This prints
console.log("value of i=" + i); // This prints
console.log("value of strikeArr=" + strikeArr); // This prints
console.log("value of masterArry[i]=" + masterArry[i]); **// This prints : value of masterArry[i]=undefined**
masterArry[i].push(strikeArr); // This DOES NOT print
console.log("Here # 2");
I don’t really know what to say other than masterArry is not what you expect it to be. If masterArry[i] is undefined, then the code won’t run (as you’re experiencing).
Is there any other collection I can think of here as alternative which can hold my 3 arrays ?
I plan extract these 3 arrays and pass to the chart library in index hbs page
What would you like to pass to the handlebars template?
I want to construct 3 arrays from this json.
for all c’s
make strikeArr for c[0].v
make callArr for c[1].v
make putArr for c[2].v
Then I want to pass these 3 arrays to handlebars to highcharts chart for plotting a graph.
Here is what my mongoose doing with the find query to get that json record out of mongo db
var colSchema=new Schema({
label:String,
type:String
});
var vSchema=new Schema({
v:String
});
var cSchema=new Schema({
c:[vSchema]
});
var openInterestDataSchema = new Schema({
_id: String,
cols:[colSchema],
rows:[cSchema],
}, {collection: 'bankniftyopeninterest'});
var bankniftyopeninterest = mongoose.model('bankniftyopeninterest', openInterestDataSchema);
bankniftyopeninterest.find().then(function(openinterestdocs) {
// I have posted processing code with openinterestdocs in previous posts
})
OK. And given the data above, what should these arrays look like?
Use the data above, i.e. { "_id" : ObjectId("5c1e78fe39601938c3e1480a"), "cols" : [ ... ]} and provide an example of what you would like to have passed through to the template.