Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

forEach Loop in React

import React from 'react';  
     
function App() {  
     
  const myArray = ['Ranjeet', 'Adil', 'Preet'];  
    
  return (  
    <div className="container" style={{background:'red'}}>     
        <h1> Example of React Map Loop </h1>  
     
        {myArray.map(name => (  
          <li>  
            {name}  
          </li>  
        ))}  
     
    </div>  
  );  
}  
     
export default App;
Comment

foreach in react

You need to pass an array of element to jsx. 
The problem is that forEach does not return anything (i.e it returns undefined).
So it's better to use map because map returns an array:

***
Comment

PREVIOUS NEXT
Code Example
Javascript :: dictionary in javascript 
Javascript :: change innertext javascript 
Javascript :: reduce() break 
Javascript :: how to use Space for vertically in antd 
Javascript :: jquery google 
Javascript :: iiee i 
Javascript :: javascript loop over dictionary 
Javascript :: what is type coercion in javascript 
Javascript :: nodejs csv to json from link 
Javascript :: remove url from string javascript 
Javascript :: authfunctions 
Javascript :: error: node_modules/react-native-reanimated/src/index.ts: 
Javascript :: js array add element 
Javascript :: jquery checkvalidity 
Javascript :: javascript isalphanumeric 
Javascript :: ityped react 
Javascript :: convert number to word js crore/lakh format 
Javascript :: json-server npm 
Javascript :: classname did not match server next js styled components 
Javascript :: js php number format 
Javascript :: get all keys in json object 
Javascript :: regex expression for password validation form validation 
Javascript :: custom attribute jquery selector 
Javascript :: javascript for...of loop to iterate over the multidimensional array 
Javascript :: react native image auto height 
Javascript :: Date gethours js 
Javascript :: react native strike through text 
Javascript :: text field material ui max input for number 
Javascript :: javascript find object in array 
Javascript :: Cookies In NodeJS 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =