JSFiddle - React, Tailwind, and code Playground

by Frangly

JavaScript

let arr = [
    [ "Female" , "Male" ],
    [ "Dinner" , "Lunch" ],
    [ "No" , "Yes" ],
    [ "1" , "2" ]
]
for(let i=arr.length-2; i>-1; i--){
	for(let j=0; j< arr[i].length; j++) {
  	item = {}
    item[arr[i][j]] = arr[i+1];
    arr[i][j] = [];
    arr[i][j] = item;
	}
  arr.pop();
}
console.log(arr);
//check below console with any external tool like beautifier
console.log(JSON.stringify(arr));