0

 $.ajax({
                        type: "POST",
                        url: "<%=Page.ResolveClientUrl("~/api/ws.asmx/GetHighPriorityInquiries") %>",
                        contentType: "application/json; charset=utf-8",                        
                        dataType: 'json',
                        success: function (data) {
                            /*console.log(data.d);*/
                            var json = $.parseJSON(data.d);
                            if (json != '') {
                                var columnsIn = json[0];
                                for (var key in columnsIn) {
                                    if (key.length != 0) {
                                        for (let ctr = 0; ctr < arr.length; ++ctr) {
                                            if (key == arr[ctr]) {
                                                validColumnsArray.push(arr[ctr]);
                                                /*console.log(validColumnsArray);*/
                                            }                                           
                                        }                                        
                                    }
                                    //else {
                                    //    console.log('No Columns');
                                    //}                                    
                                }
                                arr = [];
                                debugger;
                                $.each(json, function (i) {
                                    //TODO: populate the columns with data here

                                    for (let j = 0; j < validColumnsArray.length; ++j) {

                                        var curentCol;
                                        currentCol = validColumnsArray[j];                                        
                                        console.log(currentCol);                                        
                                        var test = JSON.stringify(json[i]);
                                        /*var arrayIndex = test.indexOf(curentCol);  */                                      
                                        console.log(test);                  
                                       
                                      
                                        
                                        arr.push(json[i].validColumnsArray[j]);     /* not storing the json data on this part */                                   
                                                                           
                                        console.log(arr);
                                       
                                    }   


                                });
                            } 
                          
                        },
                        error: function (err) {
                            alert(err.responseText);
                        }
                    }); 

enter image description here

Hi Team! I am trying to access each element of a json object. The problem is, since the columns are not static(meaning it is user defined), I have to store the selected columns in an array and then access the value of the each column based on the array. you can check the screenshot variable named "curentCol". The question is, Is it possible to append the curentCol variable to json[0] to get the specific column value (i.e. json[0].name)? I tried it but I am getting undefined when I store it to a new array. Thanks for the help.

Adrian
  • 13
  • 1
  • 5
  • 1
    Welcome to StackOverflow. You're expected to [try to solve the problem first](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). Please update your question to show what you have already tried in a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). For further information, please see [How to Ask](https://stackoverflow.com/questions/how-to-ask), and take the [tour](https://stackoverflow.com/tour) :) – Alive to die - Anant Jul 15 '23 at 12:29
  • Actually I already tried a numerous number of attempts but to no avail that is why I elected to ask for assistance. – Adrian Jul 15 '23 at 12:33
  • Hi, Thanks! I did not now that this was already asked before. Thanks again and you are a life saver. :-) – Adrian Jul 15 '23 at 13:43

0 Answers0