Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var now = new Date();
- var thisYear = now.getFullYear(); // 2020 (tahun sekarang)
- function arrayToObject(arr) {
- for (var i = 0; i < arr.length; i++) {
- var umur = 0;
- var no = i + 1;
- if (arr[i][3] == null || arr[i][3] > thisYear) {
- umur = "Invalid Birth Year";
- } else {
- umur = thisYear - arr[i][3];
- }
- var arrObject = {
- firstName: arr[i][0],
- lastName: arr[i][1],
- gender: arr[i][2],
- age: umur,
- };
- console.log(
- no + ". " + arrObject.firstName + " " + arrObject.lastName + ": "
- );
- console.log(arrObject);
- }
- }
- var people = [
- ["Bruce", "Banner", "male", 1975],
- ["Natasha", "Romanoff", "female"],
- ];
- arrayToObject(people);
- console.log();
- var people2 = [
- ["Tony", "Stark", "male", 1980],
- ["Pepper", "Pots", "female", 2023],
- ];
- arrayToObject(people2);
- arrayToObject([]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement