I am attempting to create a javascript object so that I can tranfsorm it into a json string in order to update a mysql table via php. I'm new to objects and json in javascript and so I have followed a couple of tutorials on the web but still can't seem to be getting this to work:
var idArray = [ 1, 2, 3];
var slideNo = [ 1, 2, 3];
var isPublished = [ 0, 1, 0];
var floaText = [ 1, 0 , 1];
var myObject = [];
for(var i = 0; i < idArray.length; i++) {
myObject[i] = {
slideId : idArray[i],
slideNo : slideNo [i],
isPublished : isPublished [i],
floatText : floaText [i]
};
}
alert(myObject[0].slideId);
I can't seem to get the above code work. I also tried to add quoation makrs like this:
myObject[i] = {
slideId : """ + idArray[i] + """,
slideNo : """ + slideNo[i] + """,
isPublish : """ + isPublished[i] + """,
floatText : """ + floaText[i]
};
But that doesn't seem to work either. What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…