0

I have a variable name columnDatas when I console.log(columnDatas), I am getting this

enter image description here

I want to get name frmb_escalatedpercentageformarketingexecutives41 in the console.log

enter image description here

How can I get this ? Here is the code -

`

 var columnDatas = new Array();
    function set_columns(tablename, ele) {
        var ls = $(ele).siblings('.left')[0];
        var rs = $(ele).siblings('.right')[0];      

        if($("#checkPlus").val() != '') {
            var firstTable = $("#tablename").val();
        } else {
            var firstTable = rs.name;
            console.log(columnDatas);                    // HERE IS THE LINE
        }

        if(tablename == "" || (firstTable != undefined && firstTable == "")) {
            bootbox.alert("<center><b>Error:</b> Please Select a Table</center>");
            $("#tablename").css('border-color','red');
            return;
        }

        if ((rs == undefined || rs == null) && (ls == undefined || ls == null)) {
            return;
        }

        if (columnDatas != 'null' && columnDatas[tablename] != undefined) {
            _set_column(ls, tablename);
            _set_column(rs, tablename);
        } else {

            if (columnDatas[tablename] == undefined || columnDatas[tablename] == null) {
            //  $.getJSON('index.php?module=ReportBuilder&action=json_getcolumns&tblname='+tablename+"&dbid="+dbid, function(json) {
                $.getJSON('<?php echo base_url();?>cdashboard/getfields/'+tablename, function(json) {

                    columnDatas[tablename] = json;
                    //_set_column(ls, tablename);
                    _set_column(rs, tablename);
                });
            } 

            if (firstTable != undefined && firstTable != "") {
            //  $.getJSON('index.php?module=ReportBuilder&action=json_getcolumns&tblname='+tablename+"&dbid="+dbid, function(json) {
                $.getJSON('<?php echo base_url();?>cdashboard/getfields/'+firstTable, function(json) {

                    columnDatas[tablename] = json;
                    _set_column(ls, tablename);
                    //_set_column(rs, tablename);
                });
            } 
        }
    }`
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Post your code, then we may be able to help you. – Lahiru Ashan Oct 21 '16 at 02:34
  • I forgot to mention `var columnDatas = new Array(); function someting() { console.log(columnDatas); }` ---- I dont't know what it is returning ? – Nikhilesh Dutta Oct 21 '16 at 02:36
  • if I do `$.each(columnDatas, funtion(index, value) { console.log(index); })` shows me blank – Nikhilesh Dutta Oct 21 '16 at 02:38
  • In your comment you mentioned `var columnDatas = new Array();` and then you log it using `function someting() { console.log(columnDatas); }` it, as I can see your array is empty at this point. I'm I missing something or is this full code snippet? – Lahiru Ashan Oct 21 '16 at 02:43
  • wait let me give you the function – Nikhilesh Dutta Oct 21 '16 at 02:46
  • Your root object which contains two properties of type array has the same name as one of the properties. Root object frmb_escalatedpercentageformarketingexecutives41 contains an array of frmb_escalatedpercentageformarketingexecutives41. – Vishnoo Rath Oct 21 '16 at 02:49
  • try this `console.log(columnDatas[0]);` – Lahiru Ashan Oct 21 '16 at 02:57
  • yes exactly i cannot statically get that root object as it is generated dynamically, can you help me fetch that, i only need the name ... – Nikhilesh Dutta Oct 21 '16 at 02:58
  • Possible duplicate of [Getting JavaScript object key list](http://stackoverflow.com/questions/3068534/getting-javascript-object-key-list) – Dekel Oct 21 '16 at 18:58
  • Actually, the problem was it was a Primitivevalue, I solved it at the root cause. Many thanks guys. – Nikhilesh Dutta Oct 24 '16 at 06:30

0 Answers0