Why is the JSON Object returning as undefined?

This particular array.

var theObject = [{"id":"412","thn_akademik":"20152","id_prodi":"15301","kode_mk":"20038","tanggal":"23\/8\/2016","jam_1":"17:00\t","jam_2":"19:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"558","thn_akademik":"20152","id_prodi":"15301","kode_mk":"20053","tanggal":"25\/8\/2016","jam_1":"17:00\t","jam_2":"19:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"704","thn_akademik":"20152","id_prodi":"15301","kode_mk":"20052","tanggal":"30\/8\/2016","jam_1":"17:00\t","jam_2":"19:00\t","npm":"07150100190","flag1":"0","flag2":"0"},{"id":"850","thn_akademik":"20152","id_pro...
    
for (var i = 0; i < theObject.length; i++) { 
    alert(theObject[i].kode_mk);
}

It functions properly when tested on this fiddle link.

However, upon integration into my application, it returns undefined.

Does anyone have insight into why this may be happening?

Answer №1

Here we have a unique javascript object, not to be confused with a JSON object. It seems unclear what you mean by "But when i try in on my apps in return undefined.". Which specific app are you referring to?

If your application is fetching JSON data, remember to parse it before trying to iterate through it. For example:

var json = JSON.parse(JSON_HERE); 

You can then proceed to iterate through the JSON object and access the value of kode_mk.

If you could provide some code snippets from your "app", that would be helpful. Please explain the functionality of your app and how it retrieves the JSON data.

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

When modifying the variable with an index in React JS, all objects with the same key but different indexes are also altered

I attempted to modify the array of objects, specifically creating a task list that includes user name, task description, and other details. However, when I update the task at the first index, all the objects with different array indexes also get modified. ...

Launching Stealthy Slider

I am currently having an issue with implementing Sly Slider on a free WordPress theme. I have properly enqueued the JS file, set up the HTML markup, and written a jQuery function following the documentation but it does not seem to work vertically. What cou ...

a link stretching horizontally on the webpage

While building my basic HTML site, I encountered an issue with my anchor tags (). They are extending all the way across the screen with a black background, which is part of the footer design. <!DOCTYPE html> <html ng-app="myApp"> <head> ...

Arrange the divs in numerical order based on the number of downloads

I wrote a basic code to organize parent divs based on their titles. However, when I attempted to do the same for download counts, nothing happened - no errors or actions from the code. There are two functions in total, both of which are triggered by butto ...

Showing text on an ajax loader

While making an ajax call, I have implemented functions that are called on success. To enhance user experience, I am displaying a spinner during the call and hiding it once completed. My goal is to show a message along with the spinner to indicate which fu ...

Issues encountered when attempting to send Jquery Ajax due to UTF-8 conflicts

I created a JavaScript script to send form data to my PHP backend. However, the text field was receiving it with incorrect encoding. Here is the meta tag on my website: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> Here&apo ...

Utilizing an array in a PHP URL and incorporating it into JavaScript operations

In this PHP file, I am working on validating only numeric input for text-boxes with the ids "Mobile" and "Home": $elementids = array("Mobile","Home"); $serialized = rawurlencode(serialize($elementids)); $testvar='validate-nums.php?elementids='. ...

Method for transferring all items to a new array in AngularJs

There are 2 arrays: $scope.first = [ { fName:'Alex', lName='Doe' }, { fName:'John', lName='S' } ] var second= [ { fName:'Tom', lName='M', email:'<a href="/cdn-cgi/l/email-protectio ...

Undefined property error

router.post('/:token',(req,res)=>{ let language= req.query.language let name= req.query.name let param =[] if(req.path.length == 5){ param.push({ language: language },{ name: name }) ddp.personConnected(param, function(err, response) { i ...

Tips for adjusting the horizontal position of a grid item within a map() loop

I am trying to align the text in my Timeline component from Material Ui always towards the center of the timeline. The TimelineContent contains Paper, Typography (for title and description), and an image. Currently, I have multiple TimelineContent element ...

Monitor changes to DOM elements with JavaScript Mutation Observer

Recently, I've been experimenting with a Mutation Observer and using the following configuration: config = { characterData: true, characterDataOldValue: true }; This is the structure of my HTML page: <!DOCTYPE html> <html> <head& ...

What is the best method for toggling a class to indicate the active tab in VueJS?

My goal is to set the active class on the first <li> tab by default, and then switch it to the second <li> tab when selected. I plan to use CSS to visually indicate which tab is currently active. If you would like to see the current output, ch ...

Is there a way to utilize a cookie in order for the website to recognize that I have already agreed to the terms?

It's common for websites to ask for cookie and privacy acceptance upon loading, especially in the EU. I'm looking for a way to automatically accept these cookies so I don't have to constantly click "accept all" every time I open Chrome. My ...

What are the implications of dynamically setting or changing event handlers in web development?

Looking to streamline the process of replacing standard confirm() boxes with Bootstrap modals for saving and deleting on a page. Each operation has its own button (referred to as the action button) which triggers the corresponding modal. Upon clicking the ...

What exactly is the significance of placing a term "in" within a method's parameter list in documentation?

Forgive me for what may seem like a silly question, but I prefer to clarify doubts rather than leave gaps in my knowledge. Let's look at this snippet taken from developer.mozilla.org: void initCustomEvent( in DOMString type, in boolean canBu ...

Constantly showing blank white pages on my website specifically in Internet Explorer 11

I successfully developed a website using react, babel, webpack, and backend Django framework. Everything runs smoothly on Chrome, Safari, and Firefox, but when it comes to IE11, issues arise. Initially, the site functions properly, but after navigating thr ...

Trouble Registering on My React Native Application - Possible Issue with API Connection?

I'm having trouble logging into my react native app. Every time I attempt to sign in, I encounter a 'Signup Error - Something Went Wrong" message. It seems like there might be an issue with my API, as it returns a 404 error when tested on ...

Creating a JsonPath from a soapui Json Response with groovy: A step-by-step guide

Upon receiving a SOAPUI response, I attempted to parse the JSON and display all elements (from leaf nodes) in the response. The sample JSON is as follows: Sample Json : { "BookID": 7982, "author": { "authorname&quo ...

Is it possible for two buttons to have the same 'click' function?

I am encountering an issue with duplicated buttons in my code. I have two buttons, one named Update and the other named View. Initially, both buttons work perfectly fine. However, when I duplicate these buttons, only the View button retains its functionali ...

Exploring the depths of Cordova's capabilities: implementing a striking 3D front-to-back screen flip effect

Recently, I came across an interesting app that had a unique feature. By clicking on a button, the entire screen would flip from front to back with a 3D effect on iPhone. It was quite impressive to see in action. The developer mentioned that he achieved t ...