MERN Object to Array - TechRepublic
Question
August 16, 2020 at 09:01 AM
mrsrv7

MERN Object to Array

by mrsrv7 . Updated 5 years, 9 months ago

i have a mongodb database and it contains an object which itself contains an object
eg

let 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?

All Comments