function delalert(select_rule_id) {
console.log("***** Entering delalert *****");
const arr = select_rule_id;
console.log(arr);
console.log(typeof arr);
console.log("Selected Rule id" + typeof select_rule_id);
console.log("Selected Rule id" + select_rule_id);
select_rule_id2 = Object.entries(select_rule_id)
console.log("Selected Rule id" + typeof select_rule_id2);
console.log("Selected Rule id" + select_rule_id2);
var derivationName_col = "";
var maincollection = GetTableUICollectn();
var selectrule_col = select_rule_id2.split(',');
for (var key in maincollection) {
/*for (var val in select_rule_id)*/
if (selectrule_col.includes(key)) {
var derivation_id = maincollection[key];
var derivationName = maincollection[key].Derivation_Name;
derivationName_col = derivationName_col + "<br/>" + derivationName;
}
}
console.log("NameCollection" + derivationName_col);
document.getElementById('Checked_Rule').innerHTML = derivationName_col.toString();
/*return derivationName_col;*/
console.log("***** Exiting delalert *****");
}
This is my code here select_rule_id passing as array.after that print that array it shows array.(console.log(arr);) but i print that array type it show object (console.log(typeof arr);)
I also assign that array to new variabe.till shows that array as object .I print that object also but it not shown key value type.
i attached screenshot of my browser console.
>Solution :
That is a Javascript’s behavior. We set the array but it’s actually an object. You can check if the variable is array or not using
var isArr = data instanceof Array;
var isArr = Array.isArray(data);
check this out Why does typeof array with objects return "object" and not "array"?