I have this JS:
function SetAPIValue(key1, value1, scormVersion, methodCalled) {
if (key1 == true || key1 == false) { }
else
{
alert("value1 = " + value1);
/* value1 came back with two values for cmi.suspend_data! */
var obj = {
key: key1,
value: value1
}
setValuesArray.push(obj);
}
somehow or another value1 contains two values for key1, how can I spit them when I push to my array so each value and key is in a row?
thanks
If value1
is an array containing multiple values:
function SetAPIValue(key1, value1, scormVersion, methodCalled) {
if (value1 instanceof Array) {
for (var i = 0; i < value1.length; i++) {
setValuesArray.push({
key: key1,
value: value1[i]
);
}
} else {
setValuesArray.push({
key: key1,
value: value1
});
}
}
Note this will leave you with multiple objects with the same key, which may not be desirable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.