When calling Object.keys it returns a array of the object's keys.

Object.keys({ test: '', test2: ''}) // ['test', 'test2']

When you call Array#map the function you pass will give you 2 arguments;

  1. the item in the array,
  2. the index of the item.

When you want to get the data, you need to use item (or in the example below keyName) instead of i

{Object.keys(subjects).map((keyName, i) => (
    <li className="travelcompany-input" key={i}>
        <span className="input-label">key: {i} Name: {subjects[keyName]}</span>
    </li>
))}
Answer from TryingToImprove on Stack Overflow
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Map JavaScript Object Keys Using React | Pluralsight
September 16, 2020 - I hope that this guide has helped you to understand how to iterate over a JavaScript Object's keys and how you can utilize these solutions to create compelling views using React. Access courses on AI, cloud, data, security, and more—all led by industry experts. ... Zach is currently a Lead Software Developer at OpalSoft where he uses tools such as Scala, TypeScript, Python, Docker, Node, and Angular. Zach has a passion for GIS programming along with open-source software. You can view some of his work on GitHub (https://github.com/zbennett10) and Stack Overflow (https://stackoverflow.com/users/6879849/zachary-bennett).
🌐
Bobby Hadz
bobbyhadz.com › blog › react-loop-through-object
How to Loop (or map()) through an Object in React | bobbyhadz
Copied!export default function App() { const employee = { id: 1, name: 'Bob', salary: 123, }; return ( <div> {/* 👇️ Iterate the object's KEYS */} {Object.keys(employee).map(key => { return ( <div key={key}> <h2> {key}: {employee[key]} </h2> <hr /> </div> ); })} </div> ); } The code for this article is available on GitHub · However, if you're iterating over the object's values, you can't safely use the value for the key prop, unless you can be certain that all of the values in the object are unique. The key prop is used internally by React for performance reasons.
Discussions

How can I map through an object in ReactJS?
But it throws an error of subjects.map is not a function. First, I have to define the keys of the objects where it creates an array of keys, where I want to loop through and show the subject.names. More on stackoverflow.com
🌐 stackoverflow.com
reactjs - Accessing key name in key-value pairs on props object in React - Stack Overflow
I'm working on a React app and want the component I'm working on to be able to access the key names in the props object the component is receiving. For example, I have this object: var fido = { ... More on stackoverflow.com
🌐 stackoverflow.com
arrays - Mapping object keys in react and returning child properties - Stack Overflow
I have a report that maps the number of objects. In my example there is 3 object arrays. I want to get a value of one of the properties in each object when it maps. Here is my snippet React code ... More on stackoverflow.com
🌐 stackoverflow.com
React - How to map through an object and display values from nested keys -
I have to map through an object and display all the values from all of the object keys in a list. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/reactjs › using object.keys() to turn a data object into an array, mapping the array, and passing the values as props.
r/reactjs on Reddit: Using Object.keys() to turn a data object into an array, mapping the array, and passing the values as props.
March 19, 2016 -

Right now I am making an app using the twitch api. There channels endpoint returns a data object. Since it's an object I can't map over it like normally I would if it was an array.

Thus why I am using Objects.keys(myObj) to turn the object into an array, however it's only an array of it's keys, and in order to get an array of the keys and values I have to do something like this

var myObj = {
  name: 'zack',
  age: 27,
  height: 511
};

var newArr = Object.keys(myObj);
console.log(newArr);

var mappedArr = newArr.map(function(i) {
  return [i, myObj[i]];
});

console.log(mappedArr);

the last console log is an array of my key:value pairs, but each key/value pair is in its own array.

I just want to take the object data, map through it, and pass certain parts of the objects data to a child component as props like this: https://gist.github.com/laere/eaf0fa4eb90b731f92e9

How can I achieve the same thing? Here is my code: https://gist.github.com/laere/ac142dedd253087ffda6

UPDATE I solved the issue. i realized I was being mentally retarded and not just calling the values within my component like this {myObj.name} or {myObj.whatevervalueithas}. I was overcomplicating it thinking I had to map over the data like my olther components. What a day.

🌐
Stack Overflow
stackoverflow.com › questions › 73704479 › react-how-to-map-through-an-object-and-display-values-from-nested-keys
React - How to map through an object and display values from nested keys -
You can use flat then map to achieve what you want, don't forget to pass an unique key to the div. Object.values(books).flat().map(v => <div key={v}> <span>{v}</span> </div>)
Find elsewhere
🌐
GitHub
github.com › sindresorhus › map-obj
GitHub - sindresorhus/map-obj: Map object keys and values into a new object · GitHub
import mapObject, {mapObjectSkip} from 'map-obj'; // Swap keys and values const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]); //=> {bar: 'foo'} // Convert keys to lowercase (shallow) const newObject = mapObject({FOO: true, ...
Starred by 217 users
Forked by 43 users
Languages: JavaScript 78.4% | TypeScript 21.6%
Published: Aug 14, 2018
Author: serdartkm
🌐
npm
npmjs.com › package › react-key-from-object
react-key-from-object - npm
map · npm i react-key-from-object · github.com/Poyoman39/react-key-from-object · github.com/Poyoman39/react-key-from-object#readme · 238 · 1.2.1 · LGPL-3.0-or-later · 13.9 kB · 9 · 5 months ago · poyoman · Try on RunKit ·
      » npm install react-key-from-object
    
Published: Jul 22, 2025
Version: 1.2.1
Author: Johan Maupetit
🌐
Medium
medium.com › @ismailtaufiq19 › display-objects-key-value-pairs-in-reactjs-95d8a26bd74b
Display Object’s Key-Value Pairs in ReactJS - Taufiq Ismail - Medium
August 25, 2023 - const Country = () =>{ const countryLang = { languages: { fra: "French", gsw: "Swiss German", ita: "Italian", roh: "Romansh" } } return( <div> <h2>Languages:</h2> <ul> {Object.keys(countryLang.languages).map((key, index)=>( <li key={index}>{countryLang.languages[key]}</li> ))} </ul> </div> ) } References: [1] https://www.pluralsight.com/guides/how-to-display-key-and-value-pairs-from-json-in-reactjs
🌐
DhiWise
dhiwise.com › blog › design-converter › how-to-use-react-object-map-for-clean-code
React Object Map: Best Practices For Developers
January 17, 2025 - In this example, I used the map function to transform each person object into a list item. The key prop is essential for React to identify which items have changed, are added, or are removed.
🌐
DEV Community
dev.to › mazin1231 › map-method-in-react-js-4i2o
Map() Method In React JS. - DEV Community
November 7, 2022 - What is map in JS? Map is a collection of elements where each element is stored as a Key, value pair. Map object can hold both objects and primitive values as either key or value.
🌐
Threerings
threerings.github.io › react › apidocs › react › RMap.html
RMap (react 1.5.4 API)
Returns a value view that models the mapping of the specified key in this map. The view will report a change when the mapping for the specified key is changed or removed.
🌐
DhiWise
dhiwise.com › post › mastering-react-map-a-comprehensive-guide-to-list-rendering
Understanding React Map for Efficient List Rendering
September 5, 2024 - This callback function can perform operations on the array elements, such as transforming their values. To start working with React, you must import react and react-dom into your application. These imports allow you to create React components and render them to the page. ... Let's create a function NumberList that takes an array of numbers and renders a list of those numbers in your React app. ... 1const numbers = [1, 2, 3, 4, 5]; 2 3function NumberList(props) { 4 const listItems = props.numbers.map((number) => 5 <li key={number.toString()}> 6 {number} 7 </li> 8 ); 9 return ( 10 <ul>{listItems}</ul> 11 ); 12} 13 14export default NumberList; 15
🌐
React
legacy.reactjs.org › docs › lists-and-keys.html
Lists and Keys – React
If you need the same value in your component, pass it explicitly as a prop with a different name: const content = posts.map((post) => <Post key={post.id} id={post.id} title={post.title} /> );
🌐
Reddit
reddit.com › r/reactjs › how to access react components that i stored in a map object?
r/reactjs on Reddit: How to access React components that I stored in a map object?
May 29, 2024 -

I have stored React components in a map as an alternative to long if statements.

What I have:
A map object with keys being "stage1", "stage2", etc and values being the relevant components

But I get an error on the map part that is getting the component:

This expression is not callable.
Type 'Element' has no call signatures.ts(2349)

Type '{}' is not assignable to type 'string'.ts(2322)

'ComponentMap.get' cannot be used as a JSX component.
Its type '(key: string) => ((props: customProps) => Element) | undefined' is not a valid JSX element type.
Type '(key: string) => ((props: customProps) => Element) | undefined' is not assignable to type '(props: any, deprecatedLegacyContext?: any) => ReactNode'.
Type '((props: customProps) => Element) | undefined' is not assignable to type 'ReactNode'.
Type '(props: customProps) => Element' is not assignable to type 'ReactNode'.ts(2786)

Sample example code:

const ComponentMap = new Map([ ["stage1", InitialStageComponent], 
                               ["stage2", SecondStageComponent] ]);

const inputArray = ["stage1", "stage2"];

interface customProps {
    level: string
}

function InitialStageComponent(props: customProps) {
  // some logic  
  // say thrs some prop passed down called level
  return (<>
        <h1>This is stage1 {props.level}</h1>
    </>);
}

function SecondStageComponent(props: customProps) {
  // some logic   
  // say thrs some prop passed down called level
  return (<><h2>This is stage2 {props.level}</h2></>);
}

export function Page() {
  return (<>
    {
      inputArray.map(stage => {
        // e.g stage is "stage1" and the component returned from the map would be
        //   InitialStageComponent
        return (<> <ComponentMap.get(stage) /> </>);
      })
    }
  </>)
}
🌐
GitHub
github.com › topics › key-value
key-value GitHub Topics · GitHub
Store is a lightweight shared state library by the StencilJS core team. Implements a simple key/value map that efficiently re-renders components when necessary.