I am curious if it is possible to check if the object value exists and if it exists I want to check if it is a string or an array.
// var n is a dynamic variable that is retrieved from $(this)
var d = {};
if(typeof(d[n]) == "undefined"){
d[n] = "value";
}else{
if(typeof(d[n]) == "string"){
//Convert string to array using its curent value plus an additional value
}else{
//Append value to array
}
}
Currently I am using a loop to create an object for AJAX. I have a few of the same names for the data points similar to an input with the name="name[]".
How can I accomplish this?
typeofneeds no parenthesis.d[n] = [d[n], "additional value"]? You should provide inputs and expected outputs if you want a real answer. Also, you know jQuery has$.serializeArray(), right?d[n] = [].concat(d[n],v)sames results if v is string or array