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 8423695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:47:38+00:00 2026-06-10T03:47:38+00:00

Why cant i access my array? function map(array){ for(i=0; i <=array.length; i++){ var location=array[i].location;

  • 0

Why cant i access my array?

function map(array){
    for(i=0; i <=array.length; i++){
        var location=array[i].location;
        console.log("loc"+location);
        var user = array[i].from_user;
        console.log("user"+user);
        var date = array[i].created_at;
        var profile_img = array[i].profile_img;
        var text = array[i].text;
        var contentString = text;
        //geocode(user,date, profile_img, text, contentString,location);
    }
}

It gives me undefined for every element.I want to access it and pass the variables to the geocode function.
data structure:

array=[{user: a,user_id: b,date: c,profile_img: d,text: e,contentString: f,url:
      g,location:o},{user: a,user_id: b,date: c,profile_img: d,text: e,contentString: 
      f,url:g,location:o},{user: a,user_id: b,date: c,profile_img: d,text: 
      e,contentString: f,url: g,location:s}];

dont worry about the values..!

I forgot to mention when i first made the post(question). the location of the array is inserted in the previous function whereas the array didn’t include the attribute location from previous functions

  • 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-10T03:47:39+00:00Added an answer on June 10, 2026 at 3:47 am

    When calling the function, use the object literal construct enclosed in an array literal, otherwise all values will be returned as undefined. This is how you should call your function:

    map([{ // array literal enclosing an object literal
    
        location   : 1,
        from_user  : 2,
        created_at : 3,
        profile_img: 4,
        text       : 5
    
    }]);
    

    Moreover, in your loop, change:

    for (i = 0; i <= array.length; i++ ) ...
    

    …to

    for (var i = 0; i < array.length; i++) ...
    

    If you have a pre-defined array, name it and pass it to the function like this:

    map(arrayObj)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that contains @sign in the object. I can't access that
i cant access clicked object(this) parent's class.. click same elements and different returns? this
When a class is customized, by using its outlet , you cant access its
I can't access env variables in the Rails console, while in the application they
I'm trying to create a jQuery plugin following some official best practices (function($){ var
Im trying to loop through a json files' object array to access its variables'
I'd like to access a PHP array using JavaScript after a successful POST. PHP
Does anyone know why I can't access the array keys in the generated json
I have an array inside an $.each function. I want to iterate through it
I'm filtering an array which forms a set of markers on a Google Map

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.