score:1
I believe you have already found what you were looking for but, I saw this question but no answer, still.
You just need to define a variable outside mapping and while mapping, put an if condition to find what you looking for and then equalize the result to the variable outside.
Like,
let tmpItem;
this.state.newOrder.map((mapItem) => {
if (mapItem.id == "99") {
console.log(mapItem)
tmpItem = mapItem;
}
});
score:2
It's better to use find
, but it is not supported in all browsers. Use reduce
instead of map
:
var SelectedTopicPage = React.createClass({
render: function() {
var selectedId = this.props.selectedId; // id what you need to find
var topicPage = this.props.topicPages.reduce(function(topic, current) {
return topic.topic_no == selectedId ? current : topic;
}, undefined);
return (
<SelectedTopicPageMarkup headline={topicPage.headline} key={topicPage.topic_no}>
{topicPage.description}
</SelectedTopicPageMarkup>
);
}
});
Source: stackoverflow.com
Related Query
- How to return only 1 item in an array in react using map function
- React - map function sets the input values only with the last item in the array
- How Use images from javascript array in react using filter and map function
- I can't figure out how to edit array items using a map function in React
- How to click a button into a list array items only effect the related item using React hooks
- How to loop inside map function using jsx format React JS
- Why is only the last item in a map function being changed in react app?
- How to set a defaultChecked to only first input in radio button when using map function in reactjs
- How do I get acces to only one item from map method in react js
- How to dynamically create button for calling specific action using map array in react
- React / Javascript map function - return array
- how to pass the current item to the function so that i can remove it from array in react component?
- How to map local array in React card component using Typescript?
- Only last item is added to array inside map function
- How to add items into specific Id using the react array map method
- React : how to pass and array from inside a Function to the return (JSX)
- how to map array of images into two images per list item React JS
- How to get index of the clicked images which is an item of array using React native
- How to write a simple functional component that return a array list using map method
- React - How to select all checkboxes based on one without using the map function
- Using enzyme, How to find a child component in a component react if they are result of function return
- how do i update state in react for updating the value of an object inside an array using array.map function
- How to seperate item in array using react
- How can use my object like a array using with map function
- React - How to show skeleton placeholders until Array map function ended
- How to add if statement in the map function using react
- How can I solve react array map function bug?
- How to dynamically and conditionally render select options inside of a map function using React Hooks
- How to return array from function in react js
- How to dynamically update values in Shopping Cart when one item value is changing in React JS using state in map function?
More Query from same tag
- React Testing Library: Detecting Input Pattern Rejection
- How to update side menu item list in an ionic react app after login
- after passing a state to my useState hook, it is undefined, why?
- how to hide x axis bar on apex chart?
- Data does not display right in table
- How to display inline icons in menu items?
- Prefill React Form with values
- TypeError: axios__WEBPACK_IMPORTED_MODULE_1___default.a.get(...).than is not a function
- axios doesnt post data to server
- Is React's data-binding really one way? It seems like it is two way
- Filter Inside UseEffect React Not Working
- React : All the Modal gets opened at once and only last one shows up when I'm passing props inside modal
- Fetching Data from API using UseEffect
- Automatically redirect with this.props.history.push() on component
- Invariant Violation: View config not found for name div
- Build React components with Gulp, Browserify and Babel
- Facebook event plugin in react.js disappears after click to another page link
- How to toggle the state to false on component unmount using react?
- Attach element to arrow function
- How to display an HTML Element if a variable has a certain value in jsx
- Sort react-table at mount component
- How to add new option to the select dropdown by using the input with hooks?
- Importing specific data columns from excel and displaying in Reach Application
- How to query foreign relations data along with multiple main records
- useEffect causing infinite looping with constant dependency
- React: Map an array inside object
- Typescript and React without modules - cannot find name 'React'
- Generate select option entries from variables in ReactJs
- How can I insert Variable into variable name which is imported from other file?
- How to send firebase token to backend server from android studio