The error is here:
hasLetter("a",words[]);
You are passing the first item of words
, instead of the array.
Instead, pass the array to the function:
hasLetter("a",words);
Problem solved!
Here’s a breakdown of what the problem was:
I’m guessing in your browser (chrome throws a different error), words[] == words[0]
, so when you call hasLetter("a",words[]);
, you are actually calling hasLetter("a",words[0]);
. So, in essence, you are passing the first item of words to your function, not the array as a whole.
Of course, because words
is just an empty array, words[0]
is undefined
. Therefore, your function call is actually:
hasLetter("a", undefined);
which means that, when you try to access d[ascii]
, you are actually trying to access undefined[0]
, hence the error.
Related Posts:
- Javascript Uncaught TypeError: Cannot read property ‘0’ of undefined
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Create an empty object in JavaScript with {} or new Object()?
- Checking if a key exists in a JavaScript object?
- How to append something to an array?
- Sorting an array of objects by property values
- Loop through an array in JavaScript
- How can I remove a specific item from an array?
- Find object by id in an array of JavaScript objects
- How can I access and process nested objects, arrays or JSON?
- Converting array to list in Java
- Split string into array
- Array.size() vs Array.length
- How to print elements in a vector c++
- TypeScript Objects as Dictionary types as in C#
- Data type not understood while creating a NumPy array
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
- How to create an associative array in JavaScript literal notation
- Are vectors passed to functions by value or by reference in C++
- How do I declare a 2d array in C++ using new?
- How can I create a two dimensional array in JavaScript?
- Get the last item in an array
- How do I empty an array in JavaScript?
- How can I create a two dimensional array in JavaScript?
- How to loop through an array containing objects and access their properties
- Get the last item in an array
- How to split a string into an array in Bash?
- How do you check if a variable is an array in JavaScript?
- Getting “conflicting types for function” in C, why?
- How to find the sum of an array of numbers
- Array of arrays (Python/NumPy)
- Remove Object from Array using JavaScript
- Short circuit Array.forEach like calling break
- Remove duplicate values from JS array
- Why is using “for…in” for array iteration a bad idea?
- How to convert List
to int[] in Java? - What’s the source of Error: getaddrinfo EAI_AGAIN?
- Calculating Standard Deviation & Variance in C++
- Deleting array elements in JavaScript – delete vs splice
- How to compare arrays in JavaScript?
- Better way to sum a property value in an array
- How to convert int[] into List
in Java? - Correct way of looping through C++ arrays
- When will the worst case of Merge Sort occur?
- In Java, how to append a string more efficiently?
- Merge/flatten an array of arrays
- Remove Object from Array using JavaScript
- What is the difference between ( for… in ) and ( for… of ) statements?
- What’s the difference between “Array()” and “[]” while declaring a JavaScript array?
- Most efficient way to convert an HTMLCollection to an Array
- ow to create a histogram in java
- How to remove item from array by value?
- what does .space do in mips?
- How do I remove an array item in TypeScript?
- How to handle ETIMEDOUT error?
- Remove duplicate values from JS array
- How to create an array of strings in C?
- Sorting arrays in javascript by object key value
- Initialization from incompatible pointer type warning when assigning to a pointer
- How do I check whether an array contains a string in TypeScript?
- How do you put an image file in a json object?
- Remove last item from array
- Get a random item from a JavaScript array
- Objects are not valid as a React child. If you meant to render a collection of children, use an array instead
- Badly placed ()’s error with the following shell script
- type any? has no subscript members
- Simple average function in Javascript
- Multidimensional Vectors in C++
- Java ArrayList for integers
- IndexError: index 10 is out of bounds for axis 0 with size 10
- How to change value of object which is inside an array using JavaScript or jQuery?
- use Lodash to sort array of object by value
- How to remove all duplicates from an array of objects?
- Finding the average of an array using JS
- Is there a simple way to make a random selection from an array in JavaScript or any other programming language?
- Sort array of objects by single key with date value
- How can I find the number of elements in an array?
- Array type char[] is not assignable
- Convert array to JSON
- Two-dimensional array in Swift
- Parameter name omitted error?
- C char array initialization
- How to iterate through table in Lua?
- How to sort in-place using the merge sort algorithm?
- JavaScript array to CSV
- VBA array sort function?
- console.log showing contents of array object
- console.log showing contents of array object
- How to sort 2 dimensional array by column value?
- Convert ArrayList
to java.util.List [closed] - Complex JSON nesting of objects and arrays
- Array to Hash Ruby
- How to determine if Javascript array contains an object with an attribute that equals a given value?
- How to initialize an array’s length in JavaScript?
- GCC: Array type has incomplete element type
- javascript push multidimensional array
- Find a value in an array of objects in Javascript [duplicate]
- Using the Pythagorean theorem with Java
- “Uncaught TypeError: Illegal invocation” in Chrome