Why do I get undefined when using this function?

Brandon

const array1 = [2,5,10];
    
    const arr10 = function(arr) { arr.map(x => x * 10); };
    
    console.log(arr10(array1));

arr10(array1); should return an array with every number inside array1 * 10. I don't understand why I get undefined.

NullPointer

you have to add return in function:

const array1 = [2,5,10];
const arr10 = function(arr) { return arr.map(x => x * 10); };
console.log(arr10(array1));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

When using range function to populate list why do I get list formatting error when printing with %d?

Why do MATLAB built-in function results differ from the ones i get when i define the function myself using the same expression?

why do i get undefined when i input {} in side a function that get the type of input

Why do I get 'toUpperCase' of undefined when it's clearly defined?

Why do I get an undefined error when calling a function without parameter?

Why do I get "overflow evaluating the requirement" when rewriting a function using Diesel's traits into a trait method?

Why do I get 'Cannot read property 'isValid' of undefined' when using 400 data points?

Why do I get different results when I do a manual split of test and train data as opposed to using the Python splitting function

Why do I get an Invalid Argument when using the removeLabel function in Google Script

Why do I get an error when create a function but not when a variable?

Why do I get error 424 when calling a function?

Why do I get undefined value from async function?

Why do I get a "ValueError: Shape mismatch" when using CategoricalCrossentropy loss function?

Why do I get "Undefined variable" in my custom PHP function

Why do I get an access violation when using the ReadFile() function?

Why do I get an undefined local variable or method error when using a constant, but not when using a method?

Why do I get an old object when creating a new object using let and new in a function within a service?

Why do i get undefined when passing parameter to mapped getter?

Why do i get the - TypeError: undefined is not a function error?

Why do I get py4j error in Pyspark when using the 'count' function

Why do I get a undefined variable warning when using a class and construct?

Why do I get different results when using 'hasattr' function on the class and its object for the same attribute?

Why do I get stack overflow error when I use this function for Merge Sort(using Linked Lists)?

Why do I get the same number when using rand/srand in a function before main?

Node js: Why do I get ```TypeError: Cannot read property 'json' of undefined``` when I call an async function from an express route?

Why do I get an Undefined reference error when trying to compile?

Why do I get "TypeError: Cannot read property 'length' of undefined" when using length method

Why do I get an error message when using an observeEvent with this function that works fine when not wrapped in an observer?

Why do I get the error message "undefined is not a function" when trying to cancel a promise on press?