Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Array changed into Object During the exection

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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"?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading