When attempting to access the Object data, it is returning as undefined, yet the keys are being

I have an Object with values in the following format:

    [
  {
    NameSpace: 'furuuqu',
    LocalName: 'uuurur',
    ExtensionValues: 0,
    FreeText: 'OEN',
    '$$hashKey': 'object:291'
  },
  {
    NameSpace: 'furuuqu',
    LocalName: 'uuurur',
    ExtensionValues: 1,
    FreeText: 'TWO',
    '$$hashKey': 'object:293'
  }
]

To read the data from this, I attempted to convert it into JSON using JSON.stringify. The resulting objects look something like this:

{"NameSpace":"furuuqu","LocalName":"uuurur","ExtensionValues":0,"FreeText":"OEN","$$hashKey":"object:291"}
{"NameSpace":"furuuqu","LocalName":"uuurur","ExtensionValues":1,"FreeText":"TWO","$$hashKey":"object:293"}

When looping through this to get the elements, each element is displayed with keys as follows:

Object.keys(extension).forEach(function(key) {
                  console.log(key, extension[key]);
                });

0 {
1 "
2 N
3 a
4 m
5 e

If I skip the JSON.stringify, the result is undefined but the keys are correctly identified.

for(var ex=0; ex<Extension.length; ex++)
{
    //var extension = JSON.stringify(Extension[ex]);
    
    Object.keys(Extension[ex]).forEach(function(key) {
      console.log(key, extension[key]);
    });
}

NameSpace undefined
LocalName undefined
ExtensionValues undefined
FreeText undefined
$$hashKey undefined
NameSpace undefined
LocalName undefined
ExtensionValues undefined
FreeText undefined
$$hashKey undefined

Could someone please help me understand how to properly read and display the data in this scenario?

Answer №1

let dataToQuery = [].concat(Query.Extension);

Utilize the dataToQuery variable for looping so there is no need to worry about whether Query.Extension is an Array or not.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the content within a div tag

Hey there, I have a div set up as follows: <div>1+1</div> I'm looking to send this '1+1' value over to my javascript code and calculate it to get '2'. Appreciate any help in advance! ...

JavaScript and jQuery: The Power of Dynamic Arrays

Even though my var email contains a string data, why does my array length always turn out to be 0? (I've confirmed that the data is there by using alert on var email). var emails = new Array(); //retrieve all the emails $('.emailBox ...

What about creating a PHP-MySQL voting platform?

I have implemented a PHP-MySQL voting system on my website, similar to YouTube's. I am using AJAX to execute the PHP in newtest.php. The PHP script works fine when tested individually, but when trying to implement the voting functionality through AJAX ...

Is it possible to repeat this action by swiping to the left?

I'm currently developing an app in PhoneGap and retrieving information using JSON. My goal is to trigger this function again with Ajax when I slide left. This is the code I have so far. Thank you to everyone for your assistance. $(document).ready( ...

Tips on traversing a JSON array in AngularJS using the ng-repeat directive

My service returns the following JSON data: {"categories":[{"category_id":"20","name":"Desktops"}, {"category_id":"18","name":"Laptops &amp;"},{"category_id":"25","name":"Components"}, {"category_id":"57","name":"Tablets"}, {"category_id":"17","name": ...

Is it possible that the triangulation library functions on Firefox, but encounters compatibility issues on Chrome?

Currently, I am implementing triangulation using the Poly2Tri library. This is my code: var swctx = new poly2tri.SweepContext(contour); swctx.triangulate(); var triangles = swctx.getTriangles(); for (var w = 0; w < triangles.length; w++) { pts_t ...

Data merging in stream analytics input has failed to produce any results

Trying to establish a rule within an Azure Stream Analytics job using reference data and input stream from an event hub. The JSON packet for the reference data stored in BLOB storage is as follows: { "ruleId": 1234, "Tag" : "TAG1", "metricN ...

Capture a snapshot of a webpage that includes an embedded iframe

Currently, we have a nodeJS/angular 4 website that contains an iframe from a third party (powerBI Emebdded). Our goal is to develop a feature that allows the end user to capture a screenshot of the entire page, including the content within the iframe. We ...

Utilizing various if conditions in conjunction with the jQuery chart plugin Piety

Check out this Fiddle example I'm interested in experimenting with different color combinations using a small chart plugin called piety. The documentation demonstrates how to set different colors for a pie chart: $(".bar-colours-1").peity("bar", { ...

Is it possible to modify the appearance of the element that was just clicked on?

Hello everyone, I'm currently working on a form with different inputs, all with the same class: <input type="text" name="username" class="field" /> <input type="text" name="email" class="field" /> I'm trying to figure out how to ch ...

Steps for creating a resizable and automatically hiding side menu

I am working on a side menu that can be resized, and I want it to collapse (set to zero width) when it is empty. I have considered implementing one of these features individually, but I'm not sure how to make both work together. Is there a way to ad ...

Transforming a Java object containing embedded Java objects into JSON format

Is there an easy way to serialize a Java class with nested array of Java classes into JSON format? For example, I would like to convert an instance of the below class into JSON: public class Students { private final String studentId; private final ...

Guide on passing an array of objects as arguments in Chaincode for hyperledger fabric

My current challenge involves working with an object array structured as shown below [ {"name":"heamoglobin","reading":"12"}, {"name":"mrc","reading":"3.3"}, {"name":"hct","reading":"33"} ] To pass this array as an argument for my chaincode function, ...

When accessing the defaultValue property of a select element, it will result in

Here is a typical HTML dropdown menu: <select name="email" id="email"> <option value="2" selected="selected">Before redirecting to PayPal</option> <option value="1">After payment is successful</option> <opti ...

Guide on running a MySQL query in an asynchronous function in a Node.js application

Encountering some challenges while using MySQL in a node/express JS application. It seems that when trying to access the MySQL database within an asynchronous function, the code will 'skip over' the SQL query and run synchronously. This is the co ...

What is the best way to turn off autocorrect in a textarea on IE11 without turning off spellcheck?

In my experience, disabling the spellcheck attribute seems to solve the auto-correct issue, but it also eliminates the underlining of misspelled words. <textarea id="TextArea1" spellcheck="false"></textarea> I prefer to keep spellcheck enabl ...

Populate UIPickerView with nested array in JSON format

Each object in the sites array of the JSON Data has its own array called "categories," structured like this: "sites": [ { "nid": "25109", "name": "guard.com", "url": "http:\/\/www.trial.com\/guard\/", "description": null, " ...

The type 'undefined' cannot be assigned to the type 'string | Buffer | { key: string | Buffer; passphrase: string; } | GetPublicKeyOrSecret'

Verification Code for JWT This function is used to verify a jwt using typescript. public verify( token: string, secretOrPublicKey?: string | Buffer, options?: jwt.VerifyOptions ): Promise<object | string> { if (!secretOrPublicKey) { ...

Having trouble with your angular.jg ng controller functioning properly?

Having trouble getting any content to show up from the media object! The plate object seems to be malfunctioning. <!DOCTYPE html> <html lang="en" ng-app="confusionApp"> <head> <meta charset="utf-8"> <met ...

Display notification following successful data saving in CodeIgniter

I attempted to set up a notification to appear when saving data and displaying it in the view, but it didn't work as expected using notify.js. Can someone offer some assistance? This is my save function: function save() { $data = array( ...