Why am I getting an 'undefined' when I try to call my function?

Hector Silva-Robles

I am trying to loop through an array that contains multiple arrays in it. The array looks like this. var numsArr = [ [1, 2, 3, 4], [5, 6], [7, 8, 9, 10, 11]];

I already tried doing a basic for loop (I = 0; I < numsArr.length; I++). and when I try to return numsArr[I] I get get back all the arrays but I also get an 'undefined' at the end, after all the array get returned.

This is what I have as my code.

var numsArr = [ [1, 2, 3, 4], [5, 6], [7, 8, 9, 10, 11]];

function looper(){
  for(let i = 0; i < numsArr.length; i++){
    console.log(numsArr[i])
  }
}
console.log(looper())

I expected the outcome to to be each array in the array numsArr, and it does return each array but with an 'undefined' at the end.

[ 1, 2, 3, 4 ]
[ 5, 6 ]
[ 7, 8, 9, 10, 11 ]
undefined
Hybrid

var numsArr = [ [1, 2, 3, 4], [5, 6], [7, 8, 9, 10, 11]];

function looper(){
  for(let i = 0; i < numsArr.length; i++){
    console.log(numsArr[i])
  }
}

looper()

You don't need to console.log() looper(), since it already logs the results.

Just write looper() at the bottom of your JS, and it should work fine.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why am i getting a nullpointerexception when I try to setAdapter?

Why I am getting 'Forbidden' when I try to login on my live codeigniter site?

Why am I getting an undefined?

Why am I getting an undefined 'children' call?

Why am I getting a NameError when I try to call my function?

Why my async function returns an undefined when i try to access it?

Why am I getting undefined on my console?

Why am I getting no matching function for call to

why am I getting undefined on this function?

Why am I getting an "use of undefined type" error in my code, when I have the header for it included?

Why am I getting these error messages when I try to view media files on my Android device?

Why am I getting a Segmentation fault when I try to add a new node to my linked list?

Why am I getting an "undefined function" error for a function I wrote?

why I am getting this error "undefined is not a function "

why i am getting undefined is not a function?

Why am I getting an error when I try to get a string from my table in a Jframe?

Why am I getting a Compiler error stating that my variables are undefined when I pass an array by reference?

Why am I getting NULL when I try to initiate a connection?

Why am I getting these warnings when I try to installing Pycharm in my Pop!_OS?

Why am I getting a NameError when I try to access an attribute in my class?

Why am I getting an undefined result with my calculator?

Why am I getting this TypeError when I try to slice my Pandas DataFrame?

Why am I getting a '400: Bad Request' when i try to change my Discord avatar?

Why am I getting the error "Cannot read property 'MAX_LENGTH' of undefined" when I try to connect to Elasticsearch using the JavaScript client?

Why am I getting an error message when I try to deploy my Gatsby website?

Why am i getting undefined in my console, when i try to subscribe and use my context using typescript and react

I am getting "undefined" in my API call - React

Why am i getting this error when i try to answer my own dns request?

Why am I getting question marks in my terminal as a response when I call an API (Node.js)

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive