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 :: bootstrapMaterialDatePicker min date depends on other field value 
Javascript :: javaascript localStorage get number, not string 
Javascript :: eleventy stringify 
Javascript :: how to test emited method from child component vue js 
Javascript :: javascript random to abs 
Javascript :: Rectangle star pattern in JavaScript 
Javascript :: Total shopping amount from an object in javascript 
Javascript :: use variable in form action vuejs 
Javascript :: dll node cration 
Javascript :: ract native hour input 
Javascript :: Search products by startsWith in javascript 
Javascript :: tabindex 
Javascript :: js append sample 
Javascript :: node.js core modules 
Javascript :: random bigint javascript 
Javascript :: how to return many promises in axios 
Javascript :: jq add variable 
Javascript :: screeps clear memory of dead screeps 
Javascript :: how to input struct into parameter in remix 
Javascript :: animejs code sample for keyframe property 
Javascript :: express plus es5 
Javascript :: load widget after read data from json file 
Javascript :: javascript Big decimal 
Javascript :: cpprestsdk json 
Javascript :: btoa in js string only 
Javascript :: function directory javascript 
Javascript :: Form Data error (unable to decode value) characters specials 
Javascript :: AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal: 
Javascript :: desctructuring in react with aliases 
Javascript :: convert json to .env node 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =