Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

TypeError: map is not a function

The "TypeError: map is not a function" occurs when we call the map() method on a value that is not an array. To solve the error, console.log the value you're calling the map() method on and make sure to only call map on valid arrays.



Here is an example of how the error occurs.

App.js

const App = () => {
  const obj = {};

  // ⛔️ Uncaught TypeError: map is not a function

  return (
    <div>
      {obj.map(element => {
        return <h2>{element}</h2>;
      })}
    </div>
  );
};

export default App;
Source by bobbyhadz.com #
 
PREVIOUS NEXT
Tagged: #map #function
ADD COMMENT
Topic
Name
3+1 =