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

  • Home
  • SEARCH
  • 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 6591403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:25:08+00:00 2026-05-25T17:25:08+00:00

im having trouble returning an array that contains decimal values to a variable: function

  • 0

im having trouble returning an array that contains decimal values to a variable:

function foo() {
    var coords = new Array(39.3,18.2);
    console.log(coords[1]); //successfully logs 18.2
    return coords;
}

but then…

var result = foo();
alert(result[0]);

that last one throws this error:
Uncaught TypeError: Cannot read property ‘0’ of undefined

  • 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-05-25T17:25:08+00:00Added an answer on May 25, 2026 at 5:25 pm

    As other people mentioned, alert is a function and needs parenthesis

    alert(result[0])
    

    That said, there are some extra points to note:

    1) Use array literal syntax instead of new Array

    var coords = [1.23, 3.45];
    

    Its faster and new Array has some edge cases.

    2) Most browsers have developer tools (usually reacheable by F12). This allows you to use the much more convenient console.log instead of alert.

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

Sidebar

Related Questions

I'm having some trouble returning multiple values in this program that calculates min, max,
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
I'm having trouble with the following statement, which is returning the error Sequence contains
I'm having trouble returning data from my controller using an ajax post function. What
I'm having trouble returning arrays from a custom method. It compiles fine but I
I am having trouble with my queries not returning any results. There are no
For some reason, I'm having trouble negating a double and then returning it when
I'm having trouble creating a port in Unix. This code keeps returning Error creating
I'm curious why I'm having trouble with this function. I'm downloading a PNG file
I'm new to Cocoa, and working my way through Hillegass's book. I'm having trouble

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.