I am having this array of object
const myArrayData = [
{
"user": "564b6deec50de8d827c0a51a",
"images": [
{
"image": "https://link-to-image.com.iga",
"size": 16
},
{
"image": "https://3link-to-image.com.iga2",
"size": 70
},
],
},
{
"user": "564b7527ecc479e4259edff7",
"images": [
{
"image": "https://44link-to-image.com.iga",
"size": 32
},
{
"image": "https://13link-to-image.com.iga23",
"size": 45
},
],
},
{
"user": "564e0a18c8cd4b5420a9250c",
"images": [
{
"image": "https://84link-to-image.com.iga",
"size": 120
},
{
"image": "https://93link-to-image.com.iga23",
"size": 8
},
],
},
]
I want to filter out the images array object that has a size below 20
So I should get this response which filtered out the images array object that has a size below 20
[
{
"user": "564b6deec50de8d827c0a51a",
"images": [
{
"image": "https://3link-to-image.com.iga2",
"size": 70
},
],
},
{
"user": "564b7527ecc479e4259edff7",
"images": [
{
"image": "https://44link-to-image.com.iga",
"size": 32
},
{
"image": "https://13link-to-image.com.iga23",
"size": 45
},
],
},
{
"user": "564e0a18c8cd4b5420a9250c",
"images": [
{
"image": "https://84link-to-image.com.iga",
"size": 120
}
],
},
]
How can I achieve this?
>Solution :
hey you should try this
const result = myArrayData.map(data => {
return {
user: data.user,
images: data.images.filter(item =>
item.size >= 20
),
}
})