Created with <3 with dartpad.dev.
Created
June 20, 2023 09:14
-
-
Save mandaputtra/a8714385b8baea97896e9cc3093bf489 to your computer and use it in GitHub Desktop.
poetic-aqueduct-9454
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// Ini adalah form question dan answer yang di isi oleh user | |
var listanswer = [ | |
{ 'answer': 1, 'question': 1}, | |
{ 'answer': 2, 'question': 2} | |
]; | |
// ini data yang dikirim ke server | |
var dataDikirim = { | |
'ktp': 'ktp-kucing' | |
}; | |
// Karena kirim ke server kita harus bikin object | |
// { | |
// ktp: 'ktp-kucing' | |
// questionId[1]: 1, | |
//. answerId[1]: 1, | |
// } | |
// questionId dan answerId ini dinamis dan dipisahkan dengan index | |
// mari kita bikin dulu | |
var mapped = {}; // tempat sementara buat nyimpan data question dan answer | |
for (var i = 0; i < listanswer.length; i++) { | |
// bikin key untuk Map | |
var keyOne = 'questionId[$i]'; | |
var keyTwo = 'answerId[$i]'; | |
// isi key dan value dari Map | |
mapped[keyOne] = listanswer[i]['question']; | |
mapped[keyTwo] = listanswer[i]['answer']; | |
} | |
// gabungin dataDikirim dan mapped, 2-2nya merupakan Map, | |
// kita bisa gabungin dengan ... | |
// cari saja di google "how to merge/combine map" | |
var merge = { | |
...dataDikirim, | |
...mapped | |
}; | |
// Tada tergabung gaaaeeess! | |
print(merge); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment