myObject loop not functioning properly in Internet Explorer version 10

Could someone please point out what is wrong with this code snippet?

HTML:

<div id="res"></div>

Javascript:

var myObject = {
    "a" : {
        src : "someimagepath_a.png"
    },
    "b" : {
        src : "someimagepath_b.png"
    },
};
var image_srcArr = [];
var image_src = "";
for(item in myObject)
{
   image_srcArr.push(myObject[item].src);
   // additional logic goes here
}        
document.getElementById('res').innerHTML = (image_srcArr.join(" & ") + " images used");

Issue encountered:

var image_src = "";
for(item in myObject)
{
   image_src = myObject[item].src;
   // additional logic goes here
}

This code functions correctly in Firefox and other browsers, but in IE10 myObject[item] always returns undefined even though there are values within myObject.

Answer №1

Try using the following loop: for(var element in myCollection)

var myCollection = {
    "x" : {
        url : "someimagepath_x.png"
    },
    "y" : {
        url : "someimagepath_y.png"
    },
};
var image_urlsArr = [];
var image_url = "";
for(var element in myCollection)
{
   image_urlsArr.push(myCollection[element].url);
   // more code here
}        
document.getElementById('result').innerHTML = (image_urlsArr.join(" & ") + " images were loaded");

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

Tips for decoding and processing multiple JSON objects returned from an AJAX call within the initComponent method of a Sencha Touch panel

Looking for a more efficient way to read multiple JSON objects from an AJAX request. The current code provided below is taking too long, causing other codes to execute before this one. var allVisitStore = new Ext.data.Store({ model: 'allVisit&apos ...

Redis VS RabbitMQ: A Comparison of Publish/Subscribe Reliable Messaging

Context I am working on a publish/subscribe application where messages are sent from a publisher to a consumer. The publisher and consumer are located on separate machines, and there may be occasional breaks in the connection between them. Goal The obj ...

Creating a functional component in React using TypeScript with an explicit function return type

const App: FC = () => { const addItem = () => { useState([...items, {id:1,name:'something']) } return <div>hello</div> } The linter is showing an error in my App.tsx file. warning There is a missing return type ...

The proper way to validate JSON data

After making an API call, I received the following response: [{ "1": { "name": "Euro", "iso": "EUR", "sign": "€" }, "2": { "name": "Dollar", "iso": "USD", "sign": "$" }, "3": { ...

What is the method for retrieving an attribute's value from an object that does not have key-value pairs?

My current project involves working with dynamoose and running a query that produces the following output: [ Document { cost: 100 }, lastKey: undefined, count: 1, queriedCount: undefined, timesQueried: 1 ] When I use typeof(output), it returns O ...

Error: NativeScript has encountered difficulty locating the module "@nativescript/schematics"

While attempting to generate a component called "movies" with the command tns generate component movies, I encountered the following error in the terminal log: Could not find module "@nativescript/schematics". I followed the suggestions provided in this G ...

Exploring the Versatility of Jsons with Retrofit and Kotlin

My API is delivering a polyphonic Json where the variable addon_item can be either a String or an Array. I have been struggling for days to create a CustomDezerializer for it, but so far, I haven't had any luck. Below is the Json response: ({ "c ...

Discover the method for displaying a user's "last seen at" timestamp by utilizing the seconds provided by the server

I'm looking to implement a feature that displays when a user was last seen online, similar to how WhatsApp does it. I am using XMPP and Angular for this project. After making an XMPP request, I received the user's last seen time in seconds. Now, ...

Transform JSON arrays into JSON structure

I'm currently facing an issue with converting JSON arrays to JSON format data. The output I am currently getting looks like this: https://i.stack.imgur.com/SW2NW.png However, I would like my output to be in the following format: https://i.stack.img ...

Ways to break down a collection of multiple arrays

Looking to transform an array that consists of multiple arrays into a format suitable for an external API. For example: [ [44.5,43.2,45.1] , [42, 41.2, 48.1] ] transforming into [ [44.5,42], [43.2,41.2] , [45.1, 48.1] ] My current code attempts this ...

Reactivate IntelliJ IDEA's notification for running npm install even if you have previously selected "do not show again" option

One of the great features in Intellij IDEA is that it prompts you with a notification when the package.json has been changed, asking if it should run npm install, or whichever package manager you use. I have enjoyed using this feature for many years. Howe ...

What is the most efficient way to transmit an HTML document element from a client to a server in Node JS

I am attempting to capture a snapshot of my client-side document object and send it to the Node.js server. However, when I try to convert it into a string using: JSON.stringify(document.documentElement) I encounter an issue where it becomes an empty obje ...

Issues with importing Three.js as a module - encountering an Uncaught SyntaxError:

I am currently delving into the world of three.js and working on my first project. I am following the example code provided on the three.js website. Everything runs smoothly when I have three.js stored in a folder like: js/ directory However, I am enco ...

Wordpress tabs with dynamic content

I came across a code on webdeveloper.com by Mitya that had loading content tabs and needed the page to refresh after clicking the tab button. It worked perfectly fine outside of WordPress, but when I tried implementing it into my custom theme file, it didn ...

Why is my JQuery UI droppable accept condition failing to work?

After scouring the internet for hours, I'm still stuck and can't seem to figure out what's wrong with my code: Here's the HTML snippet: <ul style="list-style:none;cursor:default;"> <li>uuu</li> <li>aaa& ...

JQuery class for swapping elements upon scrolling

I am currently working on a navigation bar that changes classes to create a fading effect for the background. The approach I have taken involves targeting the window itself and monitoring the scroll position of the user. If the user scrolls down more than ...

At what point should the term "function" be included in a ReactJS component?

As a beginner in ReactJS, I have been working through some tutorials and noticed that some code examples use the keyword function while others do not. This got me wondering what the difference is and when I should use each one. Render Example with functi ...

material-ui DropDown with an image displayed for the selected value

Can someone help me figure out how to display an image in my material-ui dropdown menu? I'm currently using version 0.19.1 and have written the following code: <DropDownMenu autoWidth style={{ width: 500, marginBottom: 30 }} underlin ...

What could be causing the issue preventing me from updating my SQL database through AJAX?

$(document).ready(function(){ $('.button').click(function(){ var clickBtnValue = $(this).val(); var ajaxurl = 'functions/delivered.php', data = {'action': clickBtnValue}; $.post(ajaxurl, da ...

Is there a way for redux-saga to pause until both actions occur at least once, regardless of the order in which they happen?

Just diving into Redux saga. I'm working on creating a saga that will fetch the initial state for the redux store from our API server. This task involves utilizing two asynchronous sagas: getCurrentUser and getGroups. The goal is to send these ajax ...