Issue
I am having problem with login return first element and last element:
Here is my array of object:
0:
pointAmountMax: 99999
pointAmountMin: 1075
rateCode: ['INAINOW']
roomPoolCode: "ZZAO"
[[Prototype]]: Object
1:
pointAmountMax: 99999
pointAmountMin: 850
rateCode: ['INAINOJ']
roomPoolCode: "TOGA"
[[Prototype]]: Object
length: 2
How can I map through the array and return the pointAmountMin
smaller number first?
So in this case I want to achieve something like this in my front end
return <p>850 - 1075</p>
Solution
To get the required output first you will need to sort the array of object in ascending order related to the property pointAmountMin.
let arrayOfObj = [
{
pointAmountMax: 99999,
pointAmountMin: 1075,
rateCode: ['INAINOW'],
roomPoolCode: "ZZAO",
},
{
pointAmountMax: 99999,
pointAmountMin: 850,
rateCode: ['INAINOJ'],
roomPoolCode: "TOGA",
}
];
arrayOfObj.sort((a, b) => {
return a.pointAmountMin - b.pointAmountMin
})
console.log(arrayOfObj)
Then collect only pointAmountMin values in an array.
const filteredResult = arrayOfObj.map(() => {
return pointAmountMin
})
You have list of all pointAmountMin property values in ascending order (minimum first) Now you can show it on UI in your required format
<p>filteredResult.join(' - ')</p>
Answered By - Ankit Katheriya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.