Question
-
Topic
-
MERN Object to Array
i have a mongodb database and it contains an object which itself contains an object
eglet retailer = new Schema({
product_brand: String,
price : {
oprice_1 : Number,dprice_2: Number,
})and i m connecting Node with it via mongoose and getting the same in React through states
this.state = {
products : [],
searchfield: ”,
retailerPrice : []
}
}componentDidMount(){
axios.get(‘http://localhost:6000/Retailer%27).then(res => {
this.setState({ products: res.data});
}).catch((err) => console.log(err))
}am using this for accessing.
when i am using this.setState({ products: res.data}); all incoming data is getting into products[] itself but i want to store the price in seperate array and display elsewhere
how can i?