i'm attempting to sort through an array where the id values match those in another id array.
the data variable is as follows:
var data = [
{
"transaksi": [
{
"_id": "5acb747c9c2be225d995a8f1",
"sebelum_jumlah_sortir": 1,
"harga_produk": 50000,
"kirim": 1,
"pembelian": "5acb747c9c2be225d995a8f9"
},
{
"_id": "5acb7a6a305ef72b7d542900",
"sebelum_jumlah_sortir": 1,
"harga_produk": 50000,
"kirim": 1,
"pembelian": "5acb7a6a305ef72b7d542908"
}
],
"_id": "5acb74239c2be225d995a8ee",
"nama_produk": "Susu"
},
{
"transaksi": [
{
"_id": "5acb747c9c2be225d995a8f2",
"sebelum_jumlah_sortir": 1,
"harga_produk": 20000,
"kirim": 1,
"pembelian": "5acb747c9c2be225d995a8f9"
},
{
"_id": "5acb7a6a305ef72b7d542901",
"sebelum_jumlah_sortir": 1,
"harga_produk": 20000,
"kirim": 1,
"pembelian": "5acb7a6a305ef72b7d542908"
}
],
"_id": "5acb74279c2be225d995a8ef",
"nama_produk": "Remot Tv"
}
]
selected id variable:
var ids = [
"5acb747c9c2be225d995a8f1",
"5acb747c9c2be225d995a8f2"
]
filter function:
var filter = function(){
for (id of ids){
for (dataTransaksi of data){
console.log(dataTransaksi.transaksi.filter(transaksi => {
return transaksi._id == id
}))
}
}
}
filter()
expected result:
[
{
"transaksi": [
{
"_id": "5acb747c9c2be225d995a8f1",
"sebelum_jumlah_sortir": 1,
"harga_produk": 50000,
"kirim": 1,
"pembelian": "5acb747c9c2be225d995a8f9"
}
]
},
{
"transaksi": [
{
"_id": "5acb747c9c2be225d995a8f2",
"sebelum_jumlah_sortir": 1,
"harga_produk": 20000,
"kirim": 1,
"pembelian": "5acb747c9c2be225d995a8f9"
}
]
}
]
actual result includes empty and split elements: https://i.sstatic.net/I8nWa.png
thank you.