Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8239211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:04:14+00:00 2026-06-07T20:04:14+00:00

I have an object in my javascript which looks like this: {data:[{t:{ level:35, longtitude:121.050321666667,

  • 0

I have an object in my javascript which looks like this:

{"data":[{"t":{
                "level":"35",
                "longtitude":"121.050321666667",
                "latitude":"14.6215366666667",
                "color":"#040098"}},
         {"t":{
                "level":"31",
                "longtitude":"121.050316666667",
                "latitude":"14.621545",
                "color":"#040098"}},
         {"t":{
                "level":"29",
                "longtitude":"121.050323333333",
                "latitude":"14.62153",
                "color":"#040098"}},
//  .....

What I would like to do is to iterate thru the contents of my object so that I will be able to push them to their respective arrays independently.
I have an array for longitude, latitude, color and level.

So I have tried the following:

var size = 0, key;
for (key in result) {
    if (result.hasOwnProperty(key)) size++;
    alert(result.data[size]);
}

–>But this only alerts me “[object Object]”

success: function(result){
    var size = 0, key;
    for (key in result) {
        for(var attr in key){
            alert(attr['latitude']);
        }
    }
}

–>This gives me Undefined result[key]

I have checked that the size of my object is only 1 thru these codes

var size = 0, key;
for (key in result) {
    if (result.hasOwnProperty(key)) size++;
}
alert(size);        

I believe that only “data” is being read. And others that are inside “data” are disregarded.

I have read this, this, enter link description here, and this but they sall seem to deal with a different structure of objects. Thanks for the help in advanced.

UPDATE
Using the console.log(), I have confirmed, if im not mistaken that only the first attribute is being fetched

t
    Object { level="35", longtitude="121.0508", latitude="14.6204083333333", more...}
color       "#040098"
latitude    "14.6204083333333"
level       "35"
longtitude  "121.0508"

I tried this

for (key in result) {
            if (result.hasOwnProperty(key)) size++;
            console.log(result.data[size]['level']);
        }

–> but it says undefined

based on the structure of my object which is

data:[{"t":{'others'},'others'...]

How am I to read everything inside “data”? Each “data” has “t”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:04:15+00:00Added an answer on June 7, 2026 at 8:04 pm

    Update: Using the for...in construct for iterating over arrays isn’t recommended. The alternative is a regular for loop (each method of course having their respective advantages):

    for(var i=0; i<results.data.length; i++){
        alert(results.data[i]['t']['latitude']);
        // etc...
    }
    

    Be careful with the structure of your JSON. Also note that the javascript foreach loop iterates over keys/indices — not values. See demo: http://jsfiddle.net/g76tN/

    success: function(result){
        var latitudes = [];
        // and so on...
    
        for (var idx in result.data ) {
            if( result.data.hasOwnProperty(idx) ){
                alert( result.data[idx]['t']['latitude'] );
    
                // So you would do something like this:
                latitudes.push ( result.data[idx]['t']['latitude'] );
                // and so on...
            }
        }
    }​
    

    Note for collecting properties of objects in an array, jQuery $.map() — or native js array map for that matter — is a neat, useful alternative.

    var latitudes = $.map( result.data, function(n){
        return n['t']['latitude'];
    });
    // and so on...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Javascript object that (very simplified) looks like this if('undefined' !== typeof(listCtrls)){
If I have a javascript object that looks like the following: { 0: [0,50],
I have an ordered array which looks like this:- [-0.0020057306590257895, 50, 0.09598853868194843, 50, 0.19398280802292264,
I have a javascript object, which I've added a number of prototyped functions to,
Can I´m asking for advice. I have function which should return javascript object function
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
I have a javascript object like so: var object = [{ id: 1, title:xyz
It's a simple question i have, I have a javascript object which is declared
I have a simpe object in javascript which has few methods..Two of them I
I'm struggling to learn object oriented javascript. I have an object constructor that looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.