score:4
Accepted answer
it seems you need filter.it will return an array of object
let a = [{
id: 1,
name: 'new york'
}, {
id: 2,
name: 'london'
}]
function b(idtosearch) {
return a.filter(item => {
return item.id === idtosearch
})
};
console.log(b(1))
score:4
try this
const type = array.isarray(this.props.cities) && this.props.cities.find(el => el.id ==this.props.enteredevent.cityid);
this.setstate({ showinoption: type ? type.name : null });
make sure the name you enter matches with any one of the object in array
Source: stackoverflow.com
Related Query
- How to find object in array and show it in React component?
- How to find most recent date from an array of object then add new field and return array in react
- How to find the count of some object property in array of objects using react and javascript?
- How to send array of objects data from child component to parent component and store in the parent object using react hooks?
- How to handle object and Array in react native?
- how to show every part of array in different form in react component
- How to map over 2 Array of object in React and render to Table
- How Can i Add Event Handlers In Reusable React Component Created from Object Array
- How to modify array within object in react component state
- How to loop an object that is inside an array and is inside an object? React
- React.js: How to find duplicates for properties in an array of object and put a progressive number on that field
- How do I map an through an array of objects and display each object individually? I want each pizza order to show
- How to type an object that contains a React component as a property and also that component's props as another property?
- Find array object by ID and return it in React
- How to check if the array of object is null using react and javascript?
- In React How to pass object using history.push from a component to child component and read data
- React Context: How do I pass an object array and display contents in Consumer?
- In React How can I fetch data and render a single object in a states array without mapping the whole thing?
- I want to show and hide a form on toggle of a radio button in React js . Im trying how to use react hooks to hide or show a component on onChange even
- How to transport a function and an object to a functional component in react
- How to find and update specific value in nested object array in typescript
- How do I map over an array of objects in React and then conditionally render a component based on a previous value?
- How to access an image link inside an object and show it using react componenets
- How to arrange nested array of object data for react table component display
- How to fetch Json nested and Make it Array of object in React
- React JS - passing info from object and array as props to child component
- How to pass a json array that comes from backend to child component using props and react hooks?
- How can i post array of object using axios formik and react js
- How to iterate over an array of object and show only the latest value in a child component?
- How to map over an object which has a unique id for each object values and return the values to a React component
More Query from same tag
- In reactjs, what is wrappedComponent.propTypes?
- How to get label text instead of the value of the antd slider
- How can I change the onClick function of a button saved in a useRef object in a react component?
- create-react-app install devDepencies in dependencies section
- How to call localhosted API from Reactjs?
- Mapping arrays reactjs
- Problem with rehydrating a tree structure in mobx-persist
- ReactJS How to call a function to change JSON dict value after setState?
- Simplifying onClick function prop
- Change Set State in Component Life Cycle React Js
- Manipulating SASS variable in React Component
- how in react-table v-7 add subRow with different value?
- Converting Class Component to Functional Component with Redux
- How Do I Get Menu Items in Select Menu for ReactJS MUI?
- Curtains Shader with react
- How to get selected row using ReactDataGrid?
- How do I keep the state of a React Component after removing others from an array?
- Console error whilst waiting for API response - React/Redux
- Values are not passing and displaying even after using useContext() in react hooks
- React Redux: Can useDispatch be used to connect to an action creator? If so , how?
- Generate a unique id in react that persist
- Material-UI: Prevent onClick from triggering for an element positioned under another in sticky Table
- React-redux connect()'s mapStateToProps being called multiple times on react-router navigation
- Can't .map() a value that seems to be Array
- React - onMouseDown/onMouseUp not triggered for left click
- How can I apply this style to my slideshow?
- TypeError: movies is undefined using React Hooks
- Select in bold a specific <li> into a React map
- How to access row's data via onClick in <td> element?
- Adding style by setTimeout to dynamically added list element REACT